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
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/…– VadimNov 10, 2011 at 19:52
-
Yes, I also noted that. But it seems that the property
features
can only be obtained fromOpenLayers.Layer.Vector
, while the objectmap
only has access toOpenLayer.Layer
. The former is inherited from the latter. Then how can I getOpenLayer.Layer.Vector
?– ChanDonNov 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_GuidiNov 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. Nov 13, 2011 at 10:03