javascript - openlayers3 loadingstrategy jsonp readFeatures 给出 'undefined is not a function'

标签 javascript jquery ajax jsonp openlayers-3

我看到,JSONP 正在浏览器的“网络监控”选项卡中加载,并且在 ajax 加载数据后,该函数正在从 JSONP 正确调用,但在加载数据后,它在 JSONP 函数调用上出现以下错误:

TypeError: undefined is not a function (evaluating 'layerSrc['lsBbox'].readFeatures(response)')
loadFeaturesBbox

<!DOCTYPE html>
<html lang="ru">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">

	<title>The Book of OpenLayers3 - Code samples</title>
	<link rel="stylesheet" href="progr/nm/ol.css" type="text/css">
	<script src="progr/nm/jquery-3.1.1.min.js" type="text/javascript"></script>
	<script src="progr/nm/ol.js" type="text/javascript"></script>
	<style type="text/css">
.map {
	width: calc(100% - 9px);
	height: 500px;
	box-shadow: 4px 4px 20px black;
	border: 3px solid blue;
	float: left;
}
.tree {
	width: auto;
	border: 3px solid red;
	background: yellow;
	float: left;
}
	</style>
</head>
<body>

<dev id='mapBbox' class='map col-sm-6'></dev>

<script>
var loadFeaturesBbox = function(response){layerSrc['lsBbox'].addFeatures(layerSrc['lsBbox'].readFeatures(response));};
var layerSrc = {
	lsBbox: new ol.source.Vector({
		format: new ol.format.GeoJSON(),
		loader: function(extent, resolution, projection){
			$.ajax({
				url: 'http://demo.opengeo.org/geoserver/wfs?service=WFS&request=GetFeature&version=1.1.0&typename=osm%3Awater_areas&outputFormat=text%2Fjavascript&format_options=callback%3AloadFeaturesBbox&srsname=EPSG%3A3857&bbox='+extent.join(','),
				dataType: 'jsonp'
			})
		},
		strategy: ol.loadingstrategy.bbox,
		projection: 'EPSG:3857'
	})
};

var layers = {
	OSM: new ol.layer.Tile({source: new ol.source.OSM()}),
	lsBbox: new ol.layer.Vector({
		source: layerSrc['lsBbox'],
		style: new ol.style.Style({
			stroke: new ol.style.Stroke({
				color: 'green',
				width: 2
			})
		})
	})
};

var view = new ol.View({
	center: ol.proj.transform([-75.923853, 45.428736], 'EPSG:4326', 'EPSG:3857'),
	maxZoom: 19,
	zoom: 10
});

var maps = {
	mapBbox: new ol.Map({
		target: 'mapBbox',
		renderer: 'canvas',
		layers: [layers['OSM'], layers['lsBbox']],
		view: view
	})
};
</script>

</body>
</html>

因此,通过 JSONP 调用加载的矢量数据不会显示在 map 上。 我该如何解决这个问题?
OpenLayers版本:v3.20.1

最佳答案

矢量源上没有 readFeatures 方法,请参阅:http://openlayers.org/en/latest/apidoc/ol.source.Vector.html 您需要对其格式进行调用,因此 source.getFormat().readFeatures

关于javascript - openlayers3 loadingstrategy jsonp readFeatures 给出 'undefined is not a function',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42130066/

相关文章:

javascript - 我无法使用 jquery 让我的动画在我的网站加载时工作

javascript - 如何向按钮添加 MouseDown 事件

javascript - 如何将变量从 Controller 传递到 application.js?

javascript - 在 native react 中链接外部组件后不能有任何值(value)

javascript - 导航栏 -> 如何突出显示一个特定链接,即使它不是当前链接?

javascript - 使用ajax切换页面与传统加载页面的方式

javascript - 如何通过 Jquery 向 C# 方法发送请求并获取其参数

javascript - 什么可能导致 "No Data Recieved ERR_EMPTY_RESPONSE"?

javascript - 如何使我的代码仅警报 'gggg' ,无法使用 jquery 删除第一个语句

javascript - Protractor:如何迭代和比较使用转发器从应用程序和场景表中获得的值