How to find all layers in Mapboxgl ? Ultimately I want to show custom layer only on water and not on land

Prasanna Elangovan picture Prasanna Elangovan · Mar 23, 2017 · Viewed 13k times · Source

I created a custom circle layer. I want to show this layer only on water and not on land. I managed to do the opposite (ie: showing the layer on land and not on water) using below command. Refer this image for better understanding

map.moveLayer('polygon','water');

Now I need to know the land layer which is used by mapboxgl so that I can call function map.moveLayer('polygon','land'); to achieve what i want.

I need help to find the different layers present in the mapboxgl-streets map. But unfortunately, Mapboxgl doesn't have map.eachLayer function.

Answer

Lucas Wojciechowski picture Lucas Wojciechowski · Mar 23, 2017

You can use the Map#getStyle method to get a serialized representation of the entire style including the layers.

map.getStyle().layers