3

I need to disable L.control.layers when user click's on a certain button and enable when it click's on a seccond button.

Is this possible?

7

You could just do it using CSS.

Select the layer control using its class leaflet-control-layers:

var lc = document.getElementsByClassName('leaflet-control-layers');

And then hide it:

lc[0].style.visibility = 'hidden';

or show it:

lc[0].style.visibility = 'visible';




In case you are using jQuery:

$('.leaflet-control-layers').hide();

and:

$('.leaflet-control-layers').show();
1
  • Great idea!. It's good solution and it works. Thanks a lot. – Toni BCN Oct 20 '17 at 12:19
1

You should keep the value returned by L.control.layers(...):

var controls = L.control.layers(baseLayers, overlays, options).addTo(map);

Now you can call map.removeControl(controls); and if you should want to add them back in again later on: map.addControl(controls);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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