Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
Just a note, it is part of the API, so layer.features is the right to get at them.… – Vadim Nov 10 '11 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 Nov 11 '11 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 Nov 11 '11 at 8:51
It works! Thank you~ – ChanDon Nov 13 '11 at 2:16
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. – Martin Algesten Nov 13 '11 at 10:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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