[GIS] Making legends for each layers and switching between them using Mapbox GL JS

layerslegendmapboxmapbox-gl

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

Best Answer

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.