What is the exact API to get all features in a vector layer in OpenLayers? Suppose I have the "map" object, within which is a "Vector Layer": how can I obtain features in the layer?

1 Answer 1


As far as I can tell, it's not part of the vector layer api OpenLayers -Vector-js.html.

vector_layer.features should do the trick, though. This is an array maintained by the layer, which saves references to each geometry it contains.

I don't know if you use the Firefox add-on called Firebug, but among other things, it makes interrogating the internals of javascript objects a breeze.

  • Just a note, it is part of the API, so layer.features is the right to get at them. dev.openlayers.org/docs/files/OpenLayers/Layer/…
    – Vadim
    Commented Nov 10, 2011 at 19:52
  • Yes, I also noted that. But it seems that the property features can only be obtained from OpenLayers.Layer.Vector, while the object map only has access to OpenLayer.Layer. The former is inherited from the latter. Then how can I get OpenLayer.Layer.Vector?
    – ChanDon
    Commented Nov 11, 2011 at 8:16
  • if you use c#or java, you need to do a cast, but here you can use use javascript magic :) if (layer.features) { //do stuff }
    – D_Guidi
    Commented Nov 11, 2011 at 8:51
  • Since vector_layer.features is somewhat internal we ended up extending the Vector layer and override the add method to keep a reference to added features. Commented Nov 13, 2011 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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