I have this JSFiddle that shows two example layers that can be toggled on and off using the Bootstrap Switch to add and remove them from the map; this works fine.

The problem I am having is updating the state of the individual layers switches when the group switch is toggled. As per the example I can create a switch to add the group of layers to the map, however the switches for the individual layers do not update to show the user that is a layer that is effected by the group of layers being added.

I thought this might be possible through the hasLayer method but I'm not entirely sure how this would be implemented.

1 Answer 1


Add the following line in the onSwitchChange event handler of your group switch:

$("[name='my-checkbox2'], [name='my-checkbox3']").bootstrapSwitch('state', state, true);

Updated JSFiddle: https://jsfiddle.net/s537t380/26/



The method state can receive an optional third parameter skip. if true, switchChange event is not executed. The default is false.

Your Answer

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

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