Thursday, 10 August 2017

Mapbox GL JS default state of toggle layers



How do I change the default state (off or on) of a toggle menu in Mapbox GL JS? The code that I'm using came from another question on this site Mapbox GLJS - group layers

























Answer



Since the layers in the map are all off by default, you can change this:


link.className = 'active';

to:



link.className = '';

If you want the state of your toggle to reflect what's in the map, it's a bit more code and you need to wait for the map to load before building the toggles. Here's a modified example that does this:
























No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...