Thursday, 22 March 2018

javascript - OL3: data from WFS is added multiple times


I added a ol.source.Vector to my map which receives data from a wfs. Currently I am using ol.loadingstrategy.bbox because there is a lot of vector data and it would take too much time to load it all at once. The problem is that whenever I change the maps extent all the data which is in old and new extent is loaded and added to the source again. For example, If I just zoom out 3 times the data near to the map's center is added to the source 4 times. Obviously, after a while the performance is pretty bad because there is just too much data loaded.


Here is my code:


var wfsSource = new ol.source.Vector({
strategy: ol.loadingstrategy.bbox,

format: new ol.format.GeoJSON(),
url: getWFSURL
});

function getWFSURL(extent){
var url = 'http://serveraddress/geoserver/ola/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ola:V_GIS_VERLEGEBER_LN_PROD&outputFormat=application/json&srsname=EPSG:31467&bbox=' + extent.join(',');
return url;
}

Is there a way to prevent OL3 from adding data multiple times?




Answer



OpenLayers does check for FIDs internally and will not add a previously added feature. So make sure that you get unique FIDs from GeoServer. If you have an incorrect configuration of your data source, you may end up getting random FIDs, and then OpenLayers cannot avoid the duplication on the client.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...