[GIS] Leaflet Layer Visibility Checkbox

javascriptlayersleafletopenlayers

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.

Best Answer

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

Related Question