6

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?

5

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