I have multiple base layers, and need to switch them programmatically, dependent on various actions and states in my application. Can't find how, for the life of me.
[GIS] How to switch base layer programmatically in MapBox/Leaflet
leafletmapbox
leafletmapbox
I have multiple base layers, and need to switch them programmatically, dependent on various actions and states in my application. Can't find how, for the life of me.
Best Answer
This tutorial serves as a good example:
1) As shown in the example, set up your base layers with a variable name that can be accessed in the function where you want to switch them programmatically.
2) Then add and remove the layers you want to add or remove. The following swaps the
grayscale
layer for thestreets
layer. This assumes that bothgrayscale
andstreets
are available within the scope of the function where you are doing the switching.3) If you are using the layers control
L.control.layers
shown in the example, then the control keeps track of what is on the map, and changes the checkboxes accordingly.