How can I extract specific information from a JSON file using openlayers.vector based on certain conditions? For example, if the "type" is equal to "etat5", I want to retrieve the URL and name.
var geojson_etat7 = new OpenLayers.Layer.Vector("etat7", {
styleMap: new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
externalGraphic: './images/Etat${url}.png',
graphicWidth: 21,
graphicHeight: 25,
graphicYOffset: -24,
===>>>>>> label : "name: ${name}"
} ),
}),
projection: epsg4326,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "data/data_etat5.geojson",
format: new OpenLayers.Format.GeoJSON()
})
});
This snippet represents my JSON database:
{
"type": "FeatureCollection",
"features": [
{
"type": "etat5",
"properties": {
"name": "test",
"amenity": "toto",
"popupContent": "popo",
"url":"5"
},
"geometry": {
"type": "Point",
"coordinates": [
26.9140625,
26.9449741808516
]
}
},
{
"type": "etat5",
"properties": {
"name": "tt",
"url":"5"
},
"geometry": {
"type": "Point",
"coordinates": [
53.15008544921875,
21.3425828520359735
]
}
},
{
"type": "etat1",
"properties": {
"name": "test",
"amenity": "toto",
"popupContent": "popo",
"url":"1"
},
"geometry": {
"type": "Point",
"coordinates": [
38.9140625,
56.9449741808516
]
}
},
{
"type": "etat1",
"properties": {"url":"1"},
"geometry": {
"type": "Point",
"coordinates": [
-2.15008544921875,
1.3425828520359735
]
}
},
{
"type": "etat2",
"properties": {
"name": "test",
"amenity": "toto",
"popupContent": "popo",
"url":"2"
},
"geometry": {
"type": "Point",
"coordinates": [
26.9140625,
46.9449741808516
]
}
},
{
"type": "etat2",
"properties": {"url":"2"},
"geometry": {
"type": "Point",
"coordinates": [
3.15008544921875,
11.3425828520359735
]
}
},
{
"type": "etat3",
"properties": {
"name": "test",
"amenity": "toto",
"popupContent": "popo",
"url":"3"
},
"geometry": {
"type": "Point",
"coordinates": [
16.9140625,
26.9449741808516
]
}
},
{
"type": "etat3",
"properties": {"url":"3"},
"geometry": {
"type": "Point",
"coordinates": [
23.15008544921875,
31.3425828520359735
]
}
},
{
"type": "etat4",
"properties": {
"name": "test",
"amenity": "toto",
"popupContent": "popo",
"url":"4"
},
"geometry": {
"type": "Point",
"coordinates": [
3.9140625,
16.9449741808516
]
}
},
{
"type": "etat4",
"properties": {"url":"4"},
"geometry": {
"type": "Point",
"coordinates": [
23.15008544921875,
71.3425828520359735
]
}
},
{
"type": "etat6",
"properties": {
"name": "test",
"amenity": "toto",
"popupContent": "popo",
"url":"6"
},
"geometry": {
"type": "Point",
"coordinates": [
16.9140625,
36.9449741808516
]
}
},
{
"type": "etat6",
"properties": {"url":"6"},
"geometry": {
"type": "Point",
"coordinates": [
43.15008544921875,
111.3425828520359735
]
}
}
]
}