Skip to content

Track Display Example

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

Add a line to the map

Parameters

Name Data Type Description
paths number[] Point coordinates [x, y], unit: meter
properties object optional; custom properties (color - color, width - width, dash - dashed line)

Return value string

The feature identifier of the added line

Task track example

TypeScript
...
try {
  // Task detail track display example
  const taskId = '************'
  const taskInfo = await this.axRobot.getTaskDetail(taskId)
  console.log('Task detail', taskInfo)
  if (taskInfo && taskInfo.taskTracks) {
    const taskTracksAll = taskInfo.taskTracks
    for (let key in taskTracksAll) {
      const areaId = key // map id; if there are multiple areaIds, it means crossing maps
      // Set the area to display on the map
      console.log('Display map', areaId)
      await this.axMap.setAreaMap(areaId, 1080);  // areaId is the map area identifier
      setTimeout(() => {
        const taskTracks = taskTracksAll[key]
        console.log(areaId + ' map track data', 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', // color
          width: 2, // width, unit: pixel
          dash: 'dash' // dashed line
        });
        console.log('Track path', paths)
      }, 1000) // Note!!!!! The delay time here must be greater than the map loading time; the track must be added and displayed only after the map rendering is completed

      break // Note: The example only shows the map and track of one map; in actual use, you need to adapt according to the data
    }
  }
} catch (e) {
  console.warn('Exception', e)
  const errText = e.errText
}
...

Robot real-time state pre-execution track example

TypeScript
...
try {
  // Pre-execution track data display example during a robot task
  // The real-time status data reported by the robot is as follows:
  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('Pre-execution track data', paths)
  if (this.tasksTrackID) { // update
    this.axMap.trackLine(this.tasksTrackID, paths, {
      color: '#f00', // color
      width: 2, // width, unit: pixel
      dash: 'dash' // dashed line
    });
  } else { // add
    this.tasksTrackID = this.axMap.addLine(paths, {
      color: '#f00', // color
      width: 2, // width, unit: pixel
      dash: 'dash' // dashed line
    });
  }
} catch (e) {
  console.warn('Exception', e)
  const errText = e.errText
}
...