Track.MovePoint
移动目标基类,负责移动目标基础操作。具体由 Track.MarkerPoint、Track.CustomPoint、Track.ModelPoint、Track.GroundPoint 进行实例化。
构造函数
| 构造函数 | 描述 |
|---|---|
| new Track.MovePoint(options: Track.movePointOptions) | 移动目标基类,负责移动目标基础操作。 |
Track.movePointOptions
移动目标配置参数。
| 参数项 | 类型 | 描述 |
|---|---|---|
| point | Point | 【必须】坐标位置 |
| rotation | number | 【可选】设置角度 |
方法
| 方法 | 返回 | 描述 |
|---|---|---|
| addToMap(map: Map) | void | 添加到地图上,轨迹线会主动调用 |
| moveTo(point: Track.TrackPoint, emit?: boolean) | void | 改变状态 |
| setPoint(latlng: Point) | void | 设置坐标 |
| getPoint() | Point | 获取坐标 |
| setRotation(rotation: number) | void | 设置旋转角 |
| getRotation() | number|undefined | 获取旋转角 |
| setProperty(property: any) | void | 设置属性 |
| getProperty() | any | 获取属性 |
| on(type: string, callback: Function) | void | 监听事件 |
| fire(type: string, args: any) | void | 触发事件 |
| off(type: string, callback: Function) | void | 移除事件 |
事件
| 事件标识 | 返回数据 | 描述 |
|---|---|---|
| Track.PointCodes.SET_TRACK_POINT | {trackPoint: [Track.TrackPoint](/api/track-track-point), emit: boolean} | 位置或角度发生改变 |
| Track.PointCodes.CHANGE_POINT | {point: [Point](./point)} | 位置改变 |
| Track.PointCodes.CHANGE_ROTATION | {rotation: number} | 旋转角改变 |
| Track.MapCodes.ADD_TO_MAP | {map: [Map](./map)} | 添加到地图 |
| Track.MapCodes.REMOVE_FROM_MAP | {map: [Map](./map)} | 从地图移除 |
| Track.MapCodes.CLICK | any | 点击事件。需要预先注册事件。 |
| Track.MapCodes.MOUSE_OVER | any | 移入事件。需要预先注册事件。 |
| Track.MapCodes.MOUSE_OUT | any | 移出事件。需要预先注册事件。 |
示例
ts
// 创建移动目标实例
const movePoint = new Track.MovePoint({
// 移动目标配置
point: new BMapGL.Point(116.404, 39.915),
rotation: 90
});
// 设置坐标
movePoint.setPoint(new BMapGL.Point(116.405, 39.916));
// 设置旋转角
movePoint.setRotation(180);
// 设置自定义属性
movePoint.setProperty({
name: '测试移动目标',
type: 'marker'
});
// 监听位置变化
movePoint.on(Track.PointCodes.CHANGE_POINT, (args) => {
console.log('位置改变:', args.point);
});
// 监听旋转角变化
movePoint.on(Track.PointCodes.CHANGE_ROTATION, (args) => {
console.log('旋转角改变:', args.rotation);
});
// 移动到指定轨迹点
const trackPoint = new Track.TrackPoint({
position: new BMapGL.Point(116.405, 39.916),
time: Date.now()
});
movePoint.moveTo(trackPoint);
// 添加到地图
movePoint.addToMap(map);