I am currently working on loading geojson data using openlayers 3. Due to the large amount of data, I am looking to transfer only the necessary information. To achieve this, I have implemented a method where I pass the resolution and extent of the current view to the webservice. Here is my code snippet:
var vectorSource = new ol.source.ServerVector({
format: new ol.format.GeoJSON(),
loader: function(extent, resolution, projection) {
var url = 'data.json?e=' + extent.join(',') + '&r=' + resolution;
$.ajax({
url: url,
success: function(data) {
vectorSource.addFeatures(vectorSource.readFeatures(data));
}
});
},
projection: 'EPSG:3857',
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource
});
var map = new ol.Map({
layers: [vector],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 0
})
});
However, I have noticed that my code only triggers the webservice call once. Can someone advise on which loading strategy I should implement in order to call the webservice every time the extent (and/or the resolution) changes?