3

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.

4
  • have you tried layer.hide() function?
    – muzaffar
    Oct 6, 2015 at 7:19
  • @muzaffar yes but not got it to work with the switch Oct 6, 2015 at 7:26
  • 1
    can you make a fiddle of leaflet case as well where it is not working?
    – muzaffar
    Oct 6, 2015 at 7:27
  • 1
    @muzaffar here you go: link Oct 6, 2015 at 9:44

1 Answer 1

7

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.