Skip to content

轨迹展示示例

this.axMap.addLine(paths, properties) -> {string}

向地图中添加点

参数

名称 数据类型 说明
paths number[] 点坐标 [x, y] 单位:米
properties object 可选;自定义属性(color-颜色、width-宽度、dash-虚线)

返回值 string

添加点的 feature 标识

任务轨迹示例

TypeScript
...
try {
  // 任务详情轨迹展示示例
  const taskId = '************'
  const taskInfo = await this.axRobot.getTaskDetail(taskId)
  console.log('任务详情', taskInfo)
  if (taskInfo && taskInfo.taskTracks) {
    const taskTracksAll = taskInfo.taskTracks
    for (let key in taskTracksAll) {
      const areaId = key // 地图id 如果有多个areaId,说明是跨地图了
      // 设置地图显示的区域
      console.log('展示地图', areaId)
      await this.axMap.setAreaMap(areaId, 1080);  // areaId 为地图区域标识
      setTimeout(() => {
        const taskTracks = taskTracksAll[key]
        console.log(areaId + '地图轨迹数据', taskTracksAll[key])
        let paths = []
        for (let i = 0; i < taskTracks.length; i++) {
          let item = taskTracks[i]
          let arr = []
          arr[0] = item.x
          arr[1] = item.y
          paths.push(arr)
        }
        this.axMap.addLine(paths, {
          color: '#f00', // 颜色
          width: 2, // 宽度,单位:像素
          dash: 'dash' // 虚线
        });
        console.log('轨迹Path', paths)
      }, 1000) // 注意!!!!! 这里的延迟时间必须大于地图加载的时间,轨迹必须在地图渲染完成才能再添加展示

      break // 注意:示例仅仅展示了一个图的地图和轨迹,实际使用需要根据数据变通
    }
  }
} catch (e) {
  console.warn('异常', e)
  const errText = e.errText
}
...

机器人实时状态预执行轨迹示例

TypeScript
...
try {
  // 机器人任务中,预执行轨迹数据展示示例
  // 机器人上报实时状态数据如下:
  let state = {
    "x": 5.14,
    "y": -18.04,
    "yaw": 1.57,
    "ori": 90,
    "floorId": "69c35c34204c425717de7044",
    "businessId": "69c35bd5204c425717de7043",
    "buildingId": "66da6f298fded280e731af7a",
    "speed": 0,
    "battery": 90,
    "isCharging": false,
    "locQuality": 100,
    "isEmergencyStop": false,
    "isManualMode": false,
    "isRemoteMode": false,
    "isGoHome": false,
    "hasObstruction": false,
    "hasPersonAhead": false,
    "dispatch": 0,
    "distance": 9.1,
    "moveState": "moving",
    "serialNum": 8475,
    "enableRcs": false,
    "robotSignal": "none",
    "isInElevator": false,
    "hasNet": true,
    "runMode": 1,
    "detourRadius": 1,
    "maxSpeed": 1.2,
    "vers": {
      "vda5050Ver": "master",
      "softVer": "master",
      "hwVer": "2.11.0-pi64",
      "packageVer": "0.4.19",
      "serialVer": null
    },
    "pid": 6,
    "errors": [],
    "taskObj": {
      "taskId": "tsn-e4897699-0788-4b29-9c55-756c089ef76f",
      "taskType": 4,
      "runType": 21,
      "sourceType": 7,
      "hasRunNum": 1,
      "taskIndex": 0,
      "totalNum": 1,
      "isPaused": true,
      "isFinish": false,
      "isCancel": false,
      "isReturn": false,
      "isInteraction": false,
      "stepIndex": 0,
      "actIndex": 3,
      "duration": 17,
      "mileage": 11.94,
      "stepNum": 2,
      "totalDis": 21.08,
      "remainingDis": 9.34,
      "target": {
        "name": "19004",
        "x": 4.08302732056267,
        "y": -8.934853815682445,
        "actType": -1
      }
    },
    "disinfect": {
      "isDryBurned": false,
      "gearType": 0
    },
    "isTesting": false,
    "path": {
      "positions": [
        [
          5.135190987154432,
          -18.037787588506887
        ],
        [
          5.139223449134561,
          -17.09624374098701
        ],
        [
          5.145666791689941,
          -15.591780817250571
        ],
        [
          5.151225130742907,
          -14.293958304964507
        ],
        [
          5.1578688846336505,
          -12.742701124837815
        ],
        [
          5.164512638524392,
          -11.191443944711121
        ],
        [
          5.164747763325516,
          -11.136544404185221
        ],
        [
          5.171273954815696,
          -9.612736994321477
        ],
        [
          5.174157191752643,
          -8.939526927542872
        ]
      ]
    }
  }
  const paths = state.path.positions
  console.log('预执行轨迹数据', paths)
  if (this.tasksTrackID) { // 更新
    this.axMap.trackLine(this.tasksTrackID, paths, {
      color: '#f00', // 颜色
      width: 2, // 宽度,单位:像素
      dash: 'dash' // 虚线
    });
  } else { // 添加
    this.tasksTrackID = this.axMap.addLine(paths, {
      color: '#f00', // 颜色
      width: 2, // 宽度,单位:像素
      dash: 'dash' // 虚线
    });
  }
} catch (e) {
  console.warn('异常', e)
  const errText = e.errText
}
...