0
votes

How can we highlight(change color) roads, footpaths or cycle paths in mapbox gl js using toggle button?

2

2 Answers

2
votes

You could use setPaintProperty to change a layer's fill color like it is done in this official Mapbox example (for a layer with "type": "fill"):

https://www.mapbox.com/mapbox-gl-js/example/color-switcher/

For a layer with "type": "line" this PaintProperty would be line-color:

https://www.mapbox.com/mapbox-gl-js/style-spec#paint-line-line-color

0
votes
var map = new mapboxgl.Map({
    ...
});

button.onclick = function (e) {
    map.setPaintProperty(layer, prepertyName, value);
};