An animation changes a single object property over time.
Example: Animatable Properties
Example: Control Animations
Call the animate() method of the object you want to animate.
var myanimation = myobject.animate(
'location', // property to animate
{ lat: 40.689, lng: -74.046 }, // end value
{
duration : 200, // animation properties
relativeDuration : 400,
easing : "out-quad",
complete : function () {
console.log( 'animation complete' );
}
}
);
400
In milliseconds.
0
Adds a duration depending on the difference from start to end value. For lat/lng properties the relativeDuration is added as milliseconds per 1000 kilometers distance from start to end location.
"in-out-quad"
An easing function that describes how the property changes over time.
See Easing Functions
false
Makes the animation jump back to the start value when it completes.
false
When used together with loop: true the animation is played back and forth.
false
Interrupts animation playback.
Function to call when the animation completes.
// shrink and remove marker
mymarker.animate( 'scale', 0.01, {
complete : function( ani ) {
this.remove();
}
} );
0.0
0.0 - 1.0
Current time of the animation as value from 0 to 1.
Reference to the animated object.
false
This property only effects the animation of lat/lng properties like a object's location. If lerpLatLng is true the lat/lng number values are interpolated (avoiding the polar regions) instead of the 3d position (shortest path).
Example: Animation lerpLatLng
mymarker.animate( 'scale', 2, {
duration: 800,
complete : myCompletionAlert,
myAlertMessage : 'Animation Complete!'
} );
function myCompletionAlert( ani ) {
alert( ani.myAlertMessage );
}
var fadeout_ani = mymarker.animate( 'opacity', 0 );
// stop fadeout if clicked
mymarker.addEventListener( 'click', function() {
if ( fadeout_ani ) fadeout_ani.stop();
this.opacity = 1;
} );
Easing functions describe how properties change over time.
Example: Animation Easing
No easing. The animation plays at constant speed.
The animation starts slowly.
The animation ends slowly.
The animation starts and ends slowly.
The animation overshoots the start and/or end value.
Rubber band effect
Rubber ball effect
This special easing function reaches the end value at half time and returns to the start value.
It is useful to draw lines as arcs with a line's offsetFlow/offsetEasing property.
Earth.Animation.Easing['my-special-easing'] = function ( time ) {
// time is a value from 0 to 1 you need to modify here
return time;
};