2

How to highlight a feature in the layer. 1st image shows the layer and 2nd image is the selected feature highlighted on click.How to do this ?

Vector Layer in Mapbox

Selected Feature Highlighted Like This

3 Answers 3

5

Assuming that the Vector Layer screenshot you've linked to has polygon data and isn't just a Raster Layer, you can use Feature State to accomplish this. Here's an example of using feature state to modify styling at runtime on the client: https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/

For your purposes, rather than using the "mousemove" & "mouseleave" events that the above example uses, you can use the "click" event to trigger your polygon's style change.


⚠️ Disclaimer: I currently work for Mapbox ⚠️

Sign up to request clarification or add additional context in comments.

2 Comments

Yes tried updating the feature state using setFeatureState function but if you look closely in the 2nd image that I have shared, the intensity of base layer of map also gets changed on click on any polygon. How to achieve that ?
It's hard to advise you on the best course of action without an idea of what your data/implementation look like. Can you share an mcve?
0

Maybe this issue can help?

https://gis.stackexchange.com/questions/326243/mapbox-gl-feature-manipulation/326394#326394

You have to alter the color properties and reset the source

Comments

0

I have solved this issue. We can use background layer with dark color and use an additional layer of the same polygon to resemble that effect by increasing background opacity of the background layer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.