Saturday, 30 July 2016

Is ServerVector broken in OpenLayers 3.5?


Is ServerVector broken in OpenLayers 3.5?


Just running the following gives an error:


var wfsTest = new ol.source.ServerVector({
format: new ol.format.GeoJSON()
});

The error is: "Object doesn't support this action"


Am I doing something wrong?? It used to work fine in previous OpenLayers 3.x versions.



Answer




According to the change log of 3.5.0:



The ol.source.ServerVector class has been removed. If you used it, for example as follows:


var source = new ol.source.ServerVector({
format: new ol.format.GeoJSON(),
loader: function(extent, resolution, projection) {
var url = …;
$.ajax(url).then(function(response) {
source.addFeatures(source.readFeatures(response));
});

},
strategy: ol.loadingstrategy.bbox,
projection: 'EPSG:3857'
});

you will need to change your code to:


var source = new ol.source.Vector({
loader: function(extent, resolution, projection) {
var url = …;
$.ajax(url).then(function(response) {

var format = new ol.format.GeoJSON();
var features = format.readFeatures(response,
{featureProjection: projection});
source.addFeatures(features);
});
},
strategy: ol.loadingstrategy.bbox
});

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...