If you're looking to animate markers in Leaflet, consider using the leaflet.animatedmarker
library. It offers similar functionality to the one you've tried and is fully compatible with the latest version of Leaflet.
To get started, follow these steps:
npm i leaflet.animatedmarker
Next, import the plugin:
import "leaflet.animatedmarker/src/AnimatedMarker";
Once imported, create an instance of the plugin when the component mounts:
...
animatedMarker;
ngOnInit() {
...
const line = L.polyline(
[
[40.6851, -73.94136],
[40.68576, -73.94149],
[40.68649, -73.94165]
],
{
color: "#02929b",
weight: 1.5
}
).addTo(map);
this.animatedMarker = L.animatedMarker(line.getLatLngs(), {
autoStart: false,
icon
});
map.addLayer(this.animatedMarker);
const group = new L.featureGroup([this.animatedMarker]);
map.fitBounds(group.getBounds());
}
startAnimation() {
this.animatedMarker.start();
}
Simply click the button below to initiate the animation:
<button (click)="startAnimation()">Start animation</button>
For a live demonstration, check out this Demo.