Remove markers from a map at the end of the animation

1

I have a map with several animated markers and would like each of them to be individually removed at the end of their movement. I'm using the Leaflet library, just like Leaflet.MovingMarker. I've already tried using the isEnded and end methods without any success.

With the latter, the following code removes only one of the markers. Full Code here

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

An event click instead of end works perfectly, any and every marker is removable, but that's not what I'm looking for:

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

I also had no luck with the isEnded method:

var ended = marker.isEnded(); 
if (ended = true) {
    console.log("this marker ended!");
    map.removeLayer(this);
}

Someone has however suggested to me that the problem may be related to closures within loops (see MDN document on the subject here ). I am also convinced that this is the problem, but no matter how hard I try, I can not find a solution.

What is it that is escaping me? Thanks in advance.

    
asked by anonymous 18.02.2016 / 03:11

0 answers