I created a map using Mapbox GL JS with several layers using this example

At the same time I don't have any spatial knowledge in Javascript. It's restrict me to create legends for each layers. The particular legend(s) must show when particular layer(s) switched on.

I find function L.mapbox.legendControl but how can I use it?

enter image description here

1 Answer 1


https://www.mapbox.com/mapbox.js/api/v3.1.1/l-mapbox-legendcontrol/ is an example for Mapbox.js which is a different library to Mapbox GL JS.

I'm afraid building the legend is something you need to build, not provided by Mapbox GL JS.

https://www.mapbox.com/assembly/examples/legends/ might help with some of the layout design.

  • Andrew, thank you for URL to page about assembly css, I really didn't know about it. But it can't help me to make changeble legend field for toggled layers.
    – krvrd
    Commented Mar 8, 2018 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.