Reputation: 2812
After looking at dev.openlayers.org/apidocs/files/OpenLayers/Layer/Vector-js.htm - it isn't clear how to extract the properties value from the geojson example below, using the following javascript:
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry":
{ "type": "MultiPoint",
"coordinates": [[[0,0]]]
},
"properties": {"test" : "this"}
}
]
}
layer = new OpenLayers.Layer.Vector("GML", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "some_url",
params: {...},
format: new OpenLayers.Format.GeoJSON()
}),
});
The way I understand it so far is that layer is an object that has contains "properties" as an attribute of the feature type. But not sure how to access it.
Any help would be appreciated. Thanks in advance!
Upvotes: 0
Views: 4209
Reputation: 3856
It's features of the layer that have properties from geojson file, not layer itself. You can access them like this:
for(var i=0; i < layer.features.length; i++){
console.log(layer.features[i].attributes.test);
}
So, property attributes
of feature object will have all the properties.
Upvotes: 2