ewoken / Leaflet.MovingMarker

A Leaflet plug-in to create moving marker
MIT License
342 stars 177 forks source link

Removing individual markers from map at the end of animation #11

Open ghost opened 8 years ago

ghost commented 8 years ago

I'm having a hard time removing each individual marker from the map as soon as they stop. Tried using methods isEnded() and end without much sucess. With (end), the following code removes only but one marker (I am guessing that it is removing the first to stop). Full code here:

marker.on('end', function() {
  map.removeLayer(this);
  });

With a click event instead of an end event, each marker is made easily removable, but then this is not what I am looking for:

marker.on('click', function() {
  map.removeLayer(this);
  });

What am I missing here?