Reputation: 417
I'm writing a program which is based on Mapbox GL JS. I have saved my layer in mapbox styles and given them some coloring.
On client side,on click of button I'm changing color of that layer by
Map.setPaintProperty(layerid,'circle-color','#ff00ff')
but now I want one more button which will reset the layer color back to original (which I gave in mapbox style).
Any thoughts?
Upvotes: 1
Views: 658
Reputation: 4281
I think you have to store the original color yourself. Before setting the new color do:
const originalColor = map.getPaintProperty(layerid, 'circle-color');
// ...set the color on click
// on reset
map.setPaintProperty(layerid, 'circle-color', originalColore);
Alternatively you can store the complete original map style by using map.getStyle()
and then resetting it with map.setStyle(originalStyle)
: https://docs.mapbox.com/mapbox-gl-js/api/#map#getstyle
Upvotes: 3