Leaflet.MovingMarker icon indicating copy to clipboard operation
Leaflet.MovingMarker copied to clipboard

[Enhancement] Adding a remove option

Open ghost opened this issue 9 years ago • 3 comments

I am attempting to add a custom option to the plugin so that, if truthy, each marker is removed at the end of the respective animation. I think this could be a really useful feature. Also, it is not trivial to remove them individually outside the plugin (please see issue #11).

With this in mind, I've added a destroyedState: 4 line in the statics properties and a remove: false line in the options properties. I've also added the following code blocks:

isDestroyed: function() {
    return this._state === L.Marker.MovingMarker.destroyedState;
}

destroy: function() {
    if (this.isDestroyed()) {
        return;
    }
    this._state = L.Marker.MovingMarker.destroyedState;
    this._removeMarker();
},

onEnd: function(map) {
    L.Marker.prototype.onEnd.call(this, map);

    if (this.options.remove && (this.isDestroyed())) {
        this.destroy();
        return;
    }
    this._removeMarker();
},

 _removeMarker: function() {
    this._state = L.Marker.MovingMarker.destroyedState;
    if (this._animRequested) {
        L.Util.cancelAnimFrame(this._animId);
        this._animRequested = false;
    }
    this.L.Marker.MovingMarker.clearLayers(this, map);
    this.L.Marker.MovingMarker = null;
},

Unfortunately, for some reason the method clearLayers isn't doing its job here.

I've a working example here

ghost avatar Feb 19 '16 15:02 ghost

@pierrebonbon did you fix your problem? I have a problem about remove the movingMarker?

jw0903 avatar Sep 30 '18 08:09 jw0903

Hi @lin559 unfortunately no, I didn't advance on this issue any further I'm afraid. It works pretty well with only one marker but didn't manage to make it work with an array.

ghost avatar Sep 30 '18 08:09 ghost

Any updates on this issue?

Gerrist avatar Nov 09 '21 15:11 Gerrist