Skip to content

Track.MovePoint

移动目标基类,负责移动目标基础操作。具体由 Track.MarkerPointTrack.CustomPointTrack.ModelPointTrack.GroundPoint 进行实例化。

构造函数

构造函数描述
new Track.MovePoint(options: Track.movePointOptions)移动目标基类,负责移动目标基础操作。

Track.movePointOptions

移动目标配置参数。

参数项类型描述
pointPoint【必须】坐标位置
rotationnumber【可选】设置角度

方法

方法返回描述
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.CLICKany点击事件。需要预先注册事件。
Track.MapCodes.MOUSE_OVERany移入事件。需要预先注册事件。
Track.MapCodes.MOUSE_OUTany移出事件。需要预先注册事件。

示例

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);

基于 MIT 许可发布