![](/img/trans.png)
[英]OpenLayers 4: WFS Layer not shown on the map when using ol.format.WFS
[英]Openlayers 3 - WFS not updating on map pan
我使用CQL過濾器根據某種類型返回積分。 然后,我向過濾器添加了一個BBOX,以將結果僅限制在地圖的當前范圍內。 這一切都正常工作。 唯一的問題是,如果我平移地圖,它不會重新加載WFS調用。 因此,如果我正確縮放了wfs濾鏡的某個點,那么如果平移到我知道有一個點的區域,除非更改縮放級別,否則那里什么也沒有。 這將更新WFS。
在我的ServerVector加載程序參數中,我調用了一個函數updateWFSURL(extent)。 我使用它根據要傳遞給CQL_FILTER的過濾器標准來構建WFS網址。 我目前沒有加載策略,我嘗試使用createTile和bbox但都沒有給我正確的結果。
這是我用來將BBOX添加到我的CQL_FILTER的代碼。 之后添加更多過濾器,並將此過濾器附加到WFS URL。
var coord1 = ol.proj.transform([extent[0], extent[1]], 'EPSG:3857', 'EPSG:4326');
var coord2 = ol.proj.transform([extent[2], extent[3]], 'EPSG:3857', 'EPSG:4326');
var filter = "&CQL_FILTER=BBOX(GEOM, " + coord1 + ", " + coord2 + ", 'EPSG:4326')";
我發現的解決方法是捕獲地圖moveend事件並從那里調用updateWFSURL(extent)。 這將在平移上正確更新,但是由於updateWFSURL從WFS加載程序和moveend事件中觸發,因此它將在縮放時被調用兩次。
我正在尋找的解決方案是要么在平底鍋上正確更新我的WFS,要么如何確定平移/縮放之間的差異,因此,如果縮放是縮放,則無法在moveend中調用該函數。
在下面添加了更多代碼。 刪除了我正在使用的geoserver網址和圖層名稱,並刪除了一些僅在ID上進行過濾的CQL過濾器。 沒有我的解決,這wfs不會更新平底鍋上的地圖。
//this function gets called on page load
function loadPointAssets() {
// Source retrieving WFS data in GeoJSON format using JSONP technique
pointAssetVector = new ol.source.ServerVector({
format: new ol.format.GeoJSON(),
loader: function (extent, resolution, projection) {
//this gets called whenever the map zooms
updateWFSURL(extent);
},
projection: 'EPSG:3857'
});
//cluster markers adds the markers to the map from the pointAssetVector
clusterMarkers();
}
function updateWFSURL(extent) {
//transform the extent to coordinates can be passed in as lat/long
var coord1 = ol.proj.transform([extent[0], extent[1]], 'EPSG:3857', 'EPSG:4326');
var coord2 = ol.proj.transform([extent[2], extent[3]], 'EPSG:3857', 'EPSG:4326');
var filter = "&CQL_FILTER=BBOX(GEOM, " + coord1 + ", " + coord2 + ", 'EPSG:4326')";
$.ajax({
//create the url with the filter
url: 'http://myGeoserverURL/wfs?' +
'service=WFS&request=GetFeature&' +
'version=1.1.0&typename=LayerName&outputFormat=text/javascript&' +
'format_options=callback:loadFeatures&' +
'srsname=EPSG:4326' + filter,
dataType: 'jsonp'
});
pointAssetVector.clear(true);
}
// Executed when data is loaded by the $.ajax method.
var loadFeatures = function (response) {
//clear the features before adding them to the source again
pointAssetVector.clear();
pointAssetVector.addFeatures(pointAssetVector.readFeatures(response));
};
您不能在同一WFS請求中同時使用CQL篩選器和BBOX。 如果您具有CQL屬性過濾器,則需要將BBOX過濾器添加為CQL過濾器。
例如,此BBOX過濾器:
bbox: extent.join(',') + ',EPSG:3857'
等效於此CQL過濾器:
cql_filter: "BBOX(geometry," + extent.join(',') + ")"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.