I have created this JSFiddle OpenLayers map that toggles the layers visibility using the bootstrap-switch.
I am looking to achieve the same with leaflet but can't seem to get the equivalent of the setVisible command in Leaflet to work with the bootstrap-switch.
This JSfiddle also includes the Leaflet version that doesn't work.
1 Answer 1
In Leaflet, in order to remove a layer from map, use this function
map.removeLayer(layer_source);
And If you want to add the same layer again, use this
map.addLayer(layer_source);
I've made a copy of your fiddle and here is working fiddle for your case
-
1Work perfectly, cheers @muzaffarJoshua Dickerson– Joshua Dickerson2015年10月06日 18:40:38 +00:00Commented Oct 6, 2015 at 18:40
-
Alas, five years later, this fiddle no longer works :-(Mawg– Mawg2021年01月11日 14:39:54 +00:00Commented Jan 11, 2021 at 14:39
Explore related questions
See similar questions with these tags.
layer.hide()
function?