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?
Asked
Active
Viewed 4.9k times
2 Answers
34
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
0
this.vectorLayer = new VectorLayer({
source: new VectorSource({
url:'https://json.extendsclass.com/bin/d4f21e1dd8ed',
format: new GeoJSON()
}),
});
this.maps.addLayer(this.vectorLayer)
var source = this.vectorLayer.getSource();
var features = source.getFeatures();
console.log(features,'FeatureData');
When we getting features from source then its returning 0 array you can see in image click here for image and in my url one feature available.