1

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.

  • 1
    Do you maybe add the new drawn shapes to the featuregroup you just removed? The featuregroup still has the layers you assigned to it, you just removed them from the map. If you now add new shapes to the group they will be invisible because the group is not assigned to the map. Maybe try currentFeatureGroup.clearLayers() instead of map.removeLayer() to empty the layergroup without removing it from the map. This way the created shapes will be deleted and new ones will be visible on the map. edit: just saw you got an answer on stackoverflow - nevermind... – Krxldfx Oct 5 '15 at 11:53
  • @Krxldfx thanks i think its valid point, i am clearing the layers but the problem is that only polyline are removed,,,, please post it as answer – Suhail Mumtaz Awan Oct 5 '15 at 12:09

Your Answer

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

Browse other questions tagged or ask your own question.