【发布时间】:2015-10-14 18:36:42
【问题描述】:
我必须使用 Openlayers 3.9.0 将 WFS 图层从我的 Geoserver 加载到我的网站。
根据the manual,加载功能有两个选项,loader(ol.FeatureLoader) 和url(ol.FeatureUrlFunction)。
我不明白两者之间的区别。他们都是用来加载特性的,loader,没有设置任何URL,看起来比较复杂。
我试试
var url = 'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
loader: function(extent){
$.ajax({
url: url,
type:'GET',
dataType: 'jsonp'
}).done(loadFeatures);
},
strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
});
var loadFeatures = function(response) {
var features = vectorSource.readFeatures(response);
vectorSource.addFeatures(features);
};
完全没有错误,但也没有任何功能。
那我就简单设置了
var url = 'http://localhost:8080/geoserver/mapname/wfs?service=WFS&'+'version=1.0.0&request=GetFeature&typeName=mapname:awesomelayer&'+'outputFormat=application/json&maxFeatures=50'
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20})),
url: function(extent, resolution, projection){return url}
});
并且工作了。
我不明白其中的区别,url 更简单、更快,并且不需要loadFeatures 函数。我红了手册,但在实践中,就代码而言,我无法理解。 loader 是什么,为什么它不设置 URL 以及何时使用它?我在这里错过了什么?
谢谢
【问题讨论】:
标签: vector openlayers-3