Skip to content

ViewAnimation

地图视角动画类,用于实现地图视角的平滑过渡动画。

构造函数

构造函数描述
BMapGL.ViewAnimation(keyFrames: Array<ViewAnimationKeyFrames>, opts: ViewAnimationOptions)创建地图视角动画对象,通过关键帧的形式对动画进行定义

ViewAnimationOptions

属性类型描述
delayNumber动画开始延迟时间,单位ms,默认0
durationNumber动画持续时间,单位ms,默认1000
interationNumber | string循环次数,参数类型为数字时循环固定次数,参数为'INFINITE'无限循环,默认为1

ViewAnimationKeyFrames

属性类型描述
centerPoint地图中心点,默认值为地图当前状态中心点
zoomNumber地图缩放级别,默认值为地图当前状态缩放级别
tiltNumber地图倾斜角度,默认值为地图当前状态倾斜角度
headingNumber地图旋转角度,默认值为地图当前旋转角度
percentageNumber表示当前关键帧处于动画过程的百分比,取值范围0~1

事件

事件名参数描述
animationstart{type: string, target: any}动画开始时触发,如果配置了delay,则在delay后触发
animationiterations{type: string, target: any}当动画循环大于1次时,上一次结束既下一次开始时触发。最后一次循环结束时不触发
animationend{type: string, target: any}动画结束时触发,如果动画中途被终止,则不会触发
animationcancel{type: string, target: any}动画中途被终止时触发

示例

ts
// 创建视角动画
const animation = new BMapGL.ViewAnimation([
  {
    center: new BMapGL.Point(116.404, 39.915),
    zoom: 12,
    percentage: 0
  },
  {
    center: new BMapGL.Point(116.404, 39.915),
    zoom: 15,
    percentage: 1
  }
], {
  duration: 2000,
  delay: 500
});

// 监听动画事件
animation.onanimationstart = function(e) {
  console.log('动画开始');
};

animation.onanimationend = function(e) {
  console.log('动画结束');
};

// 开始动画
map.startViewAnimation(animation);

基于 MIT 许可发布