我在Geoserver中有一个PostGIS类型的图层。我使用Openlayers 3.9.0在我的地图上获取它。我的代码基于官方example。
var map = new ol.Map({...//set the map
var textent = ol.proj.transformExtent([2297128.5, 4618333, 2459120.25, 4763120], 'EPSG:900913', 'EPSG:3857');
var resolution = map.getView().getResolution();
var projection = ol.proj.get('EPSG:3857');
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(textent, resolution, projection) {
return 'http://localhost:8080/geoserver/mymap/wfs?&service=wfs&version=1.1.0&request=GetFeature&typeName=mymap:mylayer&outputFormat=application/json&maxFeatures=100'
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
map.addLayer(vector);
我不太明白这段代码的作用,这个例子没有解释。我不知道这url: function(textent, resolution, projection) {
实际上做了什么。另外,我是否需要设置一个单独的功能来加载function loadFeatures(response) {...
等功能,否则这会自动发生?
当我执行代码时,我得到GET http://localhost:5550/undefined 404 (Not Found) ol-debug.js:69863
28次。 ol-debug.js
行是this.xhr_.send(content);
。节点服务器在端口5550上,Geoserver在端口8080上,我在节点上设置了反向代理,以避免CORS和ACAO错误。
请,我需要理解和调试。
由于
更多信息
在Geoserver中,当我选择GeoJSON
预览此图层时,网址为http://localhost:8080/geoserver/mymap/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=mymap:mylayer&maxFeatures=50&outputFormat=application%2Fjson
。我将其设置为矢量源的URL,但仍然会出现相同的错误。