0

I have this JSFiddle that as you can see has two tile layers. I have set the minZoom of the 'Example Layer' to 5 so that it only loads once you have zoomed in that far.

The issue is, using Bootstrap Switch I cannot get the switch for the 'Example Layer' to be disabled until the user zooms in to zoom 5 in this case and then the layer would be visible.

The ideal solution would add a tooltip to show on to the switch whilst it is disabled that advises the user to zoom in further to view the layer.

asked Jan 21, 2016 at 13:32

1 Answer 1

2

This may provide a partial answer. Use the map event listener to listen for zoomend to toggle the state of your bootstrap switch.

map.on('zoomend', function (e) {
 // enable/disable based on zoom level
 if (map.getZoom()>=5) {
 $("[name='my-checkbox2']").bootstrapSwitch('disabled',false);
 }
 else if (map.getZoom()<5) {
 $("[name='my-checkbox2']").bootstrapSwitch('disabled',true);
 }});

See the updated JSFiddle. I also set the initial state of the button to 'disabled'. When you zoom to level 5 or higher the button will become enabled, and when zoom level goes back below 5 the button will be disabled once again.

answered Jan 21, 2016 at 15:34
1
  • That's an excellent answer, thanks. I had tried an event listener but hadn't figured that bit out. I won't mark as accepted yet as it would be great if when the switch was disabled a tooltip told the user why this was the case. Commented Jan 21, 2016 at 15:53

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.