Using Mapbox's 'Toggle Layer' example, how would I load the map with the "contours" and "museums" layers turned off?

I want the layers to be turned "off" by default and have the user turn "on" the layers.

I've tried replacing

link.className = 'active';


link.className = '';

Per this question, but still doesn't work.

1 Answer 1


Additionally to what you've done replacing

link.className = 'active'; with link.className = '';,

you need to set

'visibility': 'none'

for both layers when adding them to the map:

Example: http://jsbin.com/vosenopedu/edit?html,output

  • Fantastic, thanks so much for your help! This worked perfectly!
    – pac_co
    Commented Sep 13, 2018 at 13:20

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.