Reputation: 911
Let's say i have this layer with a few attributes (id, x, y, z, year1, etc.):
var receptors1 = new ol.layer.Vector({
name: "Layer Name 1",
visible: true,
source: new ol.source.Vector({
url: "url.json",
format: new ol.format.GeoJSON()
})
});
I have a dropdown button in my app which allow the user to select a layer name from the loaded layers. Tied to this form, I have a button which needs to get the info about the layer name selected by the user and show its attributes in a new dropdown button.
I'm wondering how to access the attributes by starting at the Layer name level.
Any idea ?
Upvotes: 1
Views: 133
Reputation: 2829
To access what you need, you need to follow this logic: layer --> source --> features --> for each one --> attributes (known as properties). Here's an example:
receptors1.getSource().getFeatures().forEach(function(feature) {
console.log(feature.getProperties());
// you can also get each one individually, for example:
console.log(feature.get('year1'));
}, this);
Upvotes: 2