I have a feature with multiple elements, every element has its own geometry and an ID.
Is possible to change the style of the feature and display the elements of the feature on the map like it's own ID? For example, I have three elements, a (id = 1), b (id = 1) and c (id = 2), I want to display them on the map with 1 (for a and b) and 2 (for c). Is possible to do it?
This is my code and the JSON explains what I mean with multiple id:
var bikeStyle = new ol.style.Style({
image: new ol.style.Circle({
radius: 15,
fill: new ol.style.Fill({color: 'rgba(0, 200, 0, 1)'}),
stroke: new ol.style.Stroke({color: 'green', width: 1})
})
});
var map = new ol.Map({
target: 'map',
layers: [
...
],
view: new ol.View({
center: ol.proj.fromLonLat([11.341868,44.494949]),
zoom: 14
})
});
source = new ol.source.Vector();
bike = new ol.layer.Vector({
title: 'bikes',
source: source,
style: bikeStyle,
})
source.addFeatures(
new ol.format.GeoJSON().readFeatures(bikes, {
dataProjection: 'EPSG:4326',
featureProjection: map.getView().getProjection()
})
);
Where bike in source a json file like:
{
"type": "FeatureCollection",
"features": [{"id": 1, "type": "Feature", "geometry": {"type": "Point", "coordinates": [x,y]}, "properties": {"id": 1, "resnumb": A}}],
"features": [{"id": 13, "type": "Feature", "geometry": {"type": "Point", "coordinates": [x,y]}, "properties": {"id": 1, "resnumb": B}}],
"features": [{"id": 2, "type": "Feature", "geometry": {"type": "Point", "coordinates": [x,y]}, "properties": {"id": 2, "resnumb": C}}]
}
As you can see each element has its own id.