husq
2023-10-17 7e302c923dec48881738eac64dfc1641d7c61885
无人机位置实时更新、朝向问题解决
2 files modified
19 ■■■■ changed files
src/hooks/use-cesium-tsa.ts 13 ●●●●● patch | view | raw | blame | history
src/pages/page-web/projects/tsa.vue 6 ●●●● patch | view | raw | blame | history
src/hooks/use-cesium-tsa.ts
@@ -144,14 +144,12 @@
  const addPoint = (pointOption: pointOption) => {
    if (!pointOption.longitude && !pointOption.latitude) return
    const position = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude)
    const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(pointOption.heading, pointOption.pitch, pointOption.roll))
    viewer?.entities.add({
      position: Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude),
      position,
      billboard: pointOption.billboard,
      point: pointOption.point,
      label: pointOption.label,
      id: pointOption.id,
      orientation
    })
  }
@@ -168,17 +166,14 @@
    const pointEntity = viewer?.entities.getById(id)
    return pointEntity
  }
  // 更新实体位置
  // 更新图片实体位置
  function updateEntityPosition (longitude:number, latitude:number, id:string, params?:any) {
    const entity = getEntityById(id) as Cesium.Entity
    const position = Cesium.Cartesian3.fromDegrees(longitude, latitude)
    const heading = Cesium.Math.toRadians(params.heading)
    const pitch = Cesium.Math.toRadians(params.pitch)
    const roll = Cesium.Math.toRadians(params.roll)
    const orientation = Cesium.Transforms.headingPitchRollQuaternion(position, new Cesium.HeadingPitchRoll(heading, pitch, roll))
    const heading = Cesium.Math.toRadians(-params.heading)
    if (Cesium.defined(entity)) {
      entity.position = position
      entity.orientation = orientation
      entity.billboard.rotation = heading
    }
  }
  // 飞行 flyto
src/pages/page-web/projects/tsa.vue
@@ -332,12 +332,9 @@
    if (!droneEntity) {
      droneEntity = cesium.getEntityById('drone_fly')
    }
    console.log(data.deviceInfo[data.currentSn], '====deviceInfo====')
    if (droneEntity) {
      const orientation = {
        heading: data.deviceInfo[data.currentSn].attitude_head,
        pitch: data.deviceInfo[data.currentSn].attitude_pitch,
        roll: data.deviceInfo[data.currentSn].attitude_roll
      }
      cesium.updateEntityPosition(data.deviceInfo[data.currentSn].longitude, data.deviceInfo[data.currentSn].latitude, 'drone_fly', orientation)
    } else {
@@ -352,10 +349,9 @@
          width: 36,
          height: 36,
          scale: 1.0,
          rotation: 0.0
        },
        heading: data.deviceInfo[data.currentSn].attitude_head,
        pitch: data.deviceInfo[data.currentSn].attitude_pitch,
        roll: data.deviceInfo[data.currentSn].attitude_roll
      }
      cesium.addPoint(setting)
    }