The AMap.MoveAnimation plugin provides base classes for animating markers along lines or paths (e.g., for real-time vehicle tracking or playback). Marker, Text, and LabelMarker inherit from this implementation.
Note: You must load the plugin using AMap.plugin('AMap.MoveAnimation', ...) before using these methods.
moveTo
Moves a marker to a specific position over a set duration.
targetPosition: LngLat | Vector - The destination.opts.duration: number - Duration in milliseconds.opts.easing: EasingCallback - Timing function.opts.autoRotation: boolean - Whether the marker rotates to follow the path.
moveAlong
Moves a marker along a predefined path.
path: Array<LngLat | Vector | MoveAlongObj> - The path array.opts.duration: number | AnimationCallback - Duration per segment.opts.circlable: boolean - Whether the animation loops.opts.delay: number | AnimationCallback - Delay before starting.opts.aniInterval: number - Interval between complete animations.opts.autoRotation: boolean - Whether the marker rotates to follow the path.
// Example: moveTo
AMap.plugin('AMap.MoveAnimation', function() {
const animationMarker = new AMap.Marker({
position: new AMap.LngLat(116.397389, 39.909466),
});
animationMarker.moveTo([116.397389, 39.909466], {
duration: 1000,
delay: 500,
});
});
// Example: moveAlong with custom data
const path = [
new AMap.LngLat(116.397389, 39.909466),
new AMap.LngLat(116.379707, 39.968168),
new AMap.LngLat(116.434467, 39.95001),
new AMap.LngLat(116.46365, 39.979481),
new AMap.LngLat(116.397389, 39.909466),
];
const customData = [
{ position: path[0], duration: 200 },
{ position: path[1], duration: 400 },
{ position: path[2], duration: 600 },
{ position: path[3], duration: 800 },
{ position: path[4], duration: 1000 },
];
AMap.plugin('AMap.MoveAnimation', function() {
const animationMarker = new AMap.Marker({
position: new AMap.LngLat(116.397389, 39.909466),
angle: 90,
});
animationMarker.moveAlong(customData);
});