Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get features from vector layer in Openlayers 3

I am trying to get the features from my vector layer. The vector layer is composed from a GeoJSON document loaded via Geoserver. I tried vector.features but in vain. Could anyone help with this?

like image 939
ThisIsJ Avatar asked Mar 30 '15 16:03

ThisIsJ


1 Answers

The architecture of OL3 distinguishes between a layer and their source. So to get access to the features of a layer you first have to access the source of the layer. This is done via:

var source = layer.getSource();

In case of a vector layer you will than get a ol.source.Vector object. From this object you can access your features via:

var features = source.getFeatures();

Further you got the possibility to access special features via getFeatureById(id) or getFeaturesAtCoordinate(coordinate). For more information see the api documentation http://openlayers.org/en/v3.4.0/apidoc/ol.source.Vector.html

like image 144
jacmendt Avatar answered Oct 19 '22 08:10

jacmendt