I am using Mapbox Studio for mapping/styling and the GL JS for adding user interactivity. I want to be able to change individual polygon color on mouseenter that is part of 44 polygons total in one layer.
I've checked the Mapbox documentation/examples/tutorials and am only finding answers to using this type of feature when using map.addLayer()
it directly in the JS. I managed to change opacity but only for whole layer.
I have tried using this from another SO post but it fills all of the polygons in the entire layer in black, the backup color.
'Icons',
'icon-opacity',
['match', ['get', 'id'], 'example-id', 0.5 , 1]
My code:
map.on('mouseenter', 'pta-cos-polygons', (e) => {
const feature = e.features[0];
map.setFeatureState({
source: 'composite',
sourceLayer: 'pta-cos-polygons',
id: feature.id,
},
{hover: true}
);
map.setPaintProperty(
'pta-cos-polygons',
'fill-color',
['match', ['get', 'id'], 'feature.id', 'red', 'black']
);
});
I don't know if it's just a matter of knowing the proper syntax, but it seems that if I have the id of the specific polygon (which I do) I should be able to do this.