Skip to content Skip to sidebar Skip to footer

Mapbox Toggle All Layers Off Except One

I am new to Mapbox and javascript. I'm attempting to slightly modify a Mapbox GL code example, found here, which allows for the toggling on/off of multiple layers. I have four laye

Solution 1:

You are setting the class to active unconditionally on creation which will always make the link blue even if the layer is not visible. Try something like this.

    if(map.getLayoutProperty(id, 'visibility') === 'visible')
    {
     link.className = 'active';
    }

Though this will need to be done inside the onload function otherwise the property will be undefined.


Post a Comment for "Mapbox Toggle All Layers Off Except One"