How to set source dynamically to a layer vector in OpenLayers 3
like this
var vectorLayer= new ol.layer.Vector({
source: new ol.source.Vector()
});
vectorLayer.setSource(another_source);
Is it possible?
There is no method for setting source at api, http://openlayers.org/en/v3.0.0/apidoc/ol.layer.Vector.html. However you can define source;
var source = new ol.source.Vector();
and set source at the beginning;
var vectorLayer= new ol.layer.Vector({
source: source
});
Then you are free to add or remove features to source dynamically by using addFeature and removeFeature methods without a need of dynamic change of source.
var source = vectorLayer.getSource()
and manipulate it.