我必須從我的Geoserver加載一個WFS圖層到我的網站Openlayers 3.9.0。矢量源URL和加載器之間的區別 - openlayers 3
根據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
是simler,更快,並且不需要loadFeatures
函數。我把這本手冊弄紅了,但實際上,在代碼方面,我無法理解它。什麼是loader
,爲什麼它沒有設置網址以及何時使用它?我在這裏錯過了什麼?
謝謝
好,現在有道理。順便說一下,關於爲什麼加載程序版本不起作用的任何想法?再次感謝 – user2860857
嗨。如果你可以創建一個JSFiddle,我很樂意幫助你查看哪些問題。 –
檢查[this](http://jsfiddle.net/slevin/cn8jsdmz/1/)。我不知道爲什麼它不起作用。我使用'jQuery 1.11.3'而不是'1.11.0'。如果我用'http:// localhost:3000/geoserver/mymap/wfs'替換'http:// demo.opengeo.org/geoserver/wfs',即使看不到任何錯誤,它也不起作用。 'wfs GET'的狀態爲'200 OK'。我沒有明白,對我來說看起來很好,我可以發現錯誤。任何提示都會很棒。謝謝 – user2860857