Reputation: 3483
Introduction
As i am working on application which uses leaflet api. Live Here Where first user enter '1' as input to load the image on map.
Then user can draw different shapes(fences) using bottom-left buttons. The 'eraser' button is suppose to remove all layers from map regarding CurrentFeatureGroup.
Problem
When we click on 'eraser' button, all shapes will be removed from map having currentfeaturegroup. But after removing when we draw some other shapes, these shapes are invisible, although i have checked the function working properly. I don't have idea how these shapes are now invisible.
Script(which responsible to remove layers)
L.easyButton('<img src="/delete.png">', function () {
map.removeLayer(currentFeatureGroup);
$('.leaflet-container').css('cursor', '');
}).addTo(map);
Please consider removeLayer, not clearLayer.If someone have any idea about this problem please do help.Any kind of help or reference will be appreciated, thanks for your time
Upvotes: 0
Views: 181
Reputation: 28638
If you completely remove the featurelayer from the map by using map.removeLayer(currentFeatureLayer)
where do you expect that any new features you draw after that will be added to? If you want to remove all current features from the featurelayer you really should be using currentFeatureLayer.clearLayers()
which will keep the featurelayer so that you can continue to add features afterwards.
Upvotes: 1