husq
2023-10-17 7abab3d5474858f58ddd96bebbdf0379ddd1aa77
src/hooks/use-cesium-tsa.ts
@@ -27,6 +27,9 @@
  billboard?: billboardSetting
  label?: labelSetting
  id?: string
  heading?: number
  pitch?: number
  roll?: number
}
// 定义全局的viewer变量防止重复生成
// eslint-disable-next-line no-var
@@ -140,12 +143,15 @@
  // 添加标记点
  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),
      billboard: pointOption.billboard,
      point: pointOption.point,
      label: pointOption.label,
      id: pointOption.id,
      orientation
    })
  }
@@ -157,7 +163,24 @@
      viewer?.entities.remove(pointEntity)
    }
  }
  // 通过点ID获取实体
  function getEntityById (id:string) {
    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))
    if (Cesium.defined(entity)) {
      entity.position = position
      entity.orientation = orientation
    }
  }
  // 飞行 flyto
  const flyTo = (pointOption: pointOption, time: number = 4) => {
    if (!pointOption.longitude && !pointOption.latitude) return
@@ -256,6 +279,8 @@
    zoonIn,
    zoonOut,
    roadPattern,
    patternMap
    patternMap,
    getEntityById,
    updateEntityPosition
  }
}