У меня есть топожсон с набором объектов, таких как level1, level2, level3:
{
"type": "Topology",
"transform": …,
"objects": {
"level1": {
"id":"level1",
"type":"GeometryCollection",
"geometries":[
{"type":"Polygon","arcs":[[0]]}
]
},
"level2": …,
"level3": …,
},
"arcs": …
}
и я хотел бы определить другой цвет для другого объекта. Я использую его в openlayers 3 как векторный слой:
new ol.layer.Vector({
source: new ol.source.TopoJSON({
projection: 'EPSG:3857',
url: "url to my topojson"
}),
style: function(feature) {
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#09a7ee',
width: 1
})
});
}
})
Моя идея состоит в том, чтобы получить идентификатор объекта (level1) и выбрать цвет по нему или что-то в этом роде. Но я не знаю, как получить идентификатор свойства в функции стиля.
...
style: function(feature) {
var id = feature.get('id'); //This is not working
var colors = {
'level1': '#09a7ee',
'level2': '#aaa7ee',
...
}
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: colors[id],
width: 1
})
});
}