Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a layerGroup in leaflet?

Tags:

leaflet

it is easy to add a layerGroup to a leaflet map by simply calling layergroup.addTo(map). How I can I remove the whole layergroup from the map? I tried layergroup.eachLayer(function(layer) { map.removeLayer(layer);}); But, the map begins to behaviour weirdly.

like image 945
Jerry Yuan Avatar asked Jun 10 '15 17:06

Jerry Yuan


1 Answers

You can simply use the removeLayer method, like this:

map.removeLayer(layerGroup)

Take a look at this plunker (click on the map to remove the layer):

http://plnkr.co/edit/jSUE8ft9p7odLhQGeOVa

like image 100
Alexandru Pufan Avatar answered Sep 22 '22 10:09

Alexandru Pufan