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.

asked Oct 5, 2015 at 16:26
4
  • have you tried layer.hide() function? Commented Oct 6, 2015 at 7:19
  • @muzaffar yes but not got it to work with the switch Commented Oct 6, 2015 at 7:26
  • 1
    can you make a fiddle of leaflet case as well where it is not working? Commented Oct 6, 2015 at 7:27
  • 1
    @muzaffar here you go: link Commented 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

answered Oct 6, 2015 at 13:22
2
  • 1
    Work perfectly, cheers @muzaffar Commented Oct 6, 2015 at 18:40
  • Alas, five years later, this fiddle no longer works :-( Commented Jan 11, 2021 at 14:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.