I don't want to the show the layers control on the map, but I want to put some buttons somewhere else to change between layers. Is this possible to change the layer programmatically?
Suppose you have a map
:
var map = L.map('worldmap-map').setView([37.8, -96], 4);
To remove a layer, layer1
:
map.removeLayer(layer1)
To remove a control layer, ctrlLayer
,
map.removeControl(ctrlLayer)
Or you want to add a layer1
to map
:
layer1.addTo(map)
For an example, there is a Leaflet
example : http://leafletjs.com/examples/choropleth-example.html
You could use firebug or chrome dev tools to see its source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With