Skip to content

Commit

Permalink
Animation easing support custom function (maptalks/maptalks-canvas#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhenn committed Jan 3, 2025
1 parent 3e67549 commit 4d020be
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/map/src/core/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
isNumber,
isString,
requestAnimFrame,
now
now,
isFunction
} from './util';
import Point from '../geo/Point';
import Coordinate from '../geo/Coordinate';
Expand Down Expand Up @@ -443,8 +444,13 @@ const Animation = {
if (!options) {
options = {};
}
let easing = options['easing'] ? Easing[options['easing']] : Easing.linear;
if (!easing) {
let easing;
if (isFunction(options.easing)) {
easing = options['easing'];
} else {
easing = options['easing'] ? Easing[options['easing']] : Easing.linear;
}
if (!easing || !isFunction(easing)) {
easing = Easing.linear;
}
let dStyles, startStyles, destStyles;
Expand Down Expand Up @@ -580,7 +586,10 @@ Animation._frameFn = Animation._run.bind(Animation);
const animate = Animation.animate;
export { Animation, Easing, Player, Frame, animate };

export type EasingType = 'outExpo' | 'outQuint' | 'in' | 'out' | 'inAndOut' | 'linear' | 'upAndDown';
/**
* more animation easing functions https://echarts.apache.org/examples/zh/editor.html?c=line-easing
*/
export type EasingType = 'outExpo' | 'outQuint' | 'in' | 'out' | 'inAndOut' | 'linear' | 'upAndDown' | ((t: number) => number);

export type AnimationOptionsType = {
duration?: number;
Expand Down

0 comments on commit 4d020be

Please sign in to comment.