S
S
Sergey questions2018-06-03 19:49:21
JavaScript
Sergey questions, 2018-06-03 19:49:21

Leaflet - how to remove L.featureGroup from the map?

There is a map on leaflet, for example: https://jsfiddle.net/hc8bsd55/

Markers are added using this method:

L.featureGroup([marker_1, marker_2, marker_3]).addTo(mymap);


I'm trying to remove them on click by various methods, for example:
L.featureGroup([marker_1, marker_2, marker_3]).remove();
L.featureGroup([marker_1, marker_2, marker_3]).remove(mymap);


But nothing comes out. Can you tell me how to remove markers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-02-11
@smartycms

In your script, in the click handler, you create another featureGroup and immediately delete it. However, the first featureGroup you created remains.
Change the code to this and it will work:

// Добавляем маркеры на карту
  var feature = L.featureGroup([marker_1, marker_2, marker_3]).addTo(mymap);


  $(document).on('click', '.delete', function(e){
    feature.remove();
    return false;
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question