MapContext.moveAlong
基础库 2.34.0 开始支持本方法,低版本需做兼容处理,这是一个异步方法。
沿指定路径移动 marker,用于轨迹回放等场景。动画完成时触发回调事件,若动画进行中,对同一 marker 再次调用 moveAlong 方法,前一次的动画将被打断。
语法
MapContext.moveAlong(options)
参数说明
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
markerId | number | 是 | 指定 marker 的 id | 2.34.0 | |
path | LngLat[] | 是 | 移动路径的经纬度数组 | 2.34.0 | |
autoRotate | boolean | true | 否 | 根据路径方向自动改变 marker 的旋转角度 | 2.34.0 |
duration | number | 1000 | 否 | 平滑移动的时间,单位毫秒 | 2.34.0 |
animationEnd | function | 否 | 动画结束的回调函数,无参回调 | 2.34.0 | |
success | function | 否 | 接口调用成功的回调函数 | 2.34.0 | |
fail | function | 否 | 接口调用失败的回调函数 | 2.34.0 | |
complete | function | 否 | 接口调用结束的回调函数 | 2.34.0 |
LngLat 类型说明
object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
longitude | number | 是 | 经度 | 2.34.0 | |
latitude | number | 是 | 纬度 | 2.34.0 |
回调成功
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "MapContext.moveAlong:ok" | 2.34.0 |
回调失败
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "MapContext.moveAlong:fail" + 详细错误信息 | 2.34.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
<map id="myMap" style="width: 100%; height: 400px;" markers="{{markers}}"></map>
<view>
<button bindtap="moveAlong" type="primary">moveAlong</button>
</view>
Page({
data: {
markers: [
{
id: 1,
latitude: 23.099994,
longitude: 113.32452,
},
],
},
onReady() {
this.mapCtx = tt.createMapContext("myMap", this);
},
moveAlong() {
this.mapCtx.moveAlong({
markerId: 1,
path: [
{
latitude: 23.199994,
longitude: 113.32452,
},
{
latitude: 23.099994,
longitude: 113.42452,
},
],
animationEnd() {
tt.showToast({
title: "动画结束", // 内容
});
},
});
},
});
Bug & Tip
- Tip: 开发者工具暂不支持调试该 api,请在真机上调试。
点击纠错
该文档是否对你的开发有所帮助?
有帮助
没帮助
该文档是否对你的开发有所帮助?
有帮助
没帮助