Can i add two sources to Vector layer, i want regular feature source, and geojson source?

Maybe can I do something like:

var layer = new ol.layer.Vector({source: VectorSource, GeoJsonSource});

My reason why i need to sources to one Vector layer because i have two different sources to load the features geojson and regular lat long.


Try to create a new source and add features from both sources to this new source, then pass this source to your layer

var featuresToPass = VectorSource.getFeatures().concat(GeoJsonSource.getFeatures());
var mysource = new ol.source.Vector({
//using a collection the features in the source and the collection will stay in sync
features: featuresToPass //new ol.Collection(featuresToPass) 
var layer = new ol.layer.Vector({source:mysource});

I have not test it.

  • i don't see how does it answer my quesiton... i need two different soruces to the same Layer.. – Elad Israeli Jan 19 '16 at 18:22
  • 1
    Obviously you can not attach 2 sources in the same layer. Read the docs if you want to be sure. I suggest you a way to overcome it. If you think it doesnt answer to your question , dont worry you dont have to pay. – pavlos Jan 20 '16 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.