I am struggling with building OL3 Vector layer BBOX strategy loading. So far I can easily load Geojson file with valid json syntax, however this is one time strategy. My another approach was to use ol.ServerVector which to my understading returns Javascript with callback, but I can't make it work.
Working simple Geojson layer:
var vectorSource = new ol.source.GeoJSON(
({
projection: 'EPSG:3857',
preFeatureInsert: function(feature) {
feature.geometry.transform('EPSG:4326', 'EPSG:3857');
},
url: 'geojson2.json'
}));
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunction
});
BBOX attempt (This is returning json while moving , however features are not loading to the map ) :
var vectorSource = new ol.source.ServerVector({
format: new ol.format.GeoJSON(),
loader: function(extent, resolution, projection) {
var url = 'geojson2.php?p='+
extent.join(',');
$.ajax({
url: url
});
},
strategy: ol.loadingstrategy.bbox,
projection: 'EPSG:3857',
});
// callback ?
var loadFeatures = function(response) {
vectorSource.addFeatures(vectorSource.readFeatures(response));
};
JSON response example:
{"type":"FeatureCollection","features":[
{"type":"Feature","geometry":{"type":"Point","coordinates":[0,0]},"properties":{"label":"122.234-10/163"}},
{"type":"Feature","geometry":{"type":"Point","coordinates":[1,1],"properties":{"label":"132.222-1126"}}}
]}