1

I have created a map in leaflet and added an overlay as:

map.layerscontrol.addOverlay(tile_layer,"{{ resource.title }}");
map.addLayer(tile_layer);

The map shows great and the layer as well. Now I want to remove the 'layer switcher' controller. How can I do that in Leaflet?

  • 1
    just remove 'map.layerscontrol();' – Shahzad Bacha May 18 '16 at 13:07
  • Even if I remove the first line of the code, the layer.control is still there displaying the base layers. How can I remove it completely? – user1919 May 18 '16 at 13:17
  • What version of Leaflet are you using? How do you instantiate the map? It does not seem to me that you should have a Layers Control by default, nor that map.layerscontrol would be assigned without explicitly creating such a control. – ghybs May 18 '16 at 13:31
  • Yes. That's true. I use a specific app of django for leaflet (django-leaflet) which automates the creation of this controler. But the question is how I can later remove the controller through js. – user1919 May 18 '16 at 13:32
2

All controls in Leaflet should inherit the removeFrom method, so to remove your existing layerscontrol, you can use:

map.layerscontrol.removeFrom(map);
1

Current versions of leaflet do not add a L.Control.Layers to the map by default. I suggest you check if you're using a recent version, and check if you are manually adding a layers control somewhere.

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.