guoshilong
2023-10-18 53bcb7e5dffa071d2c6593f5db7f0b6e4e2f8dfe
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,8 +143,9 @@
  // 添加标记点
  const addPoint = (pointOption: pointOption) => {
    if (!pointOption.longitude && !pointOption.latitude) return
    const position = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude)
    viewer?.entities.add({
      position: Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude),
      position,
      billboard: pointOption.billboard,
      point: pointOption.point,
      label: pointOption.label,
@@ -157,7 +161,21 @@
      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)
    if (Cesium.defined(entity)) {
      entity.position = position
      entity.billboard.rotation = heading
    }
  }
  // 飞行 flyto
  const flyTo = (pointOption: pointOption, time: number = 4) => {
    if (!pointOption.longitude && !pointOption.latitude) return
@@ -220,7 +238,6 @@
  // 切换不同背景图层
  const patternMap = () => {
    const imageryLayers = viewer?.scene.imageryLayers
    console.log(imageryLayers, 'imageryLayers')
    // 切换为标准图层
    if (store.state.common.mapSetting.mode === 0) {
      const tdtImg_c = imageryLayers?._layers.find(v => v.imageryProvider._layer === 'tdtImg_c')
@@ -230,7 +247,6 @@
    } else {
      const tdtStand_c = imageryLayers?._layers.find(v => v.imageryProvider.credit.html === 'stand_tc')
      const tdtStand_zj = imageryLayers?._layers.find(v => v.imageryProvider.credit.html === 'stand_zj')
      console.log(tdtStand_c, tdtStand_zj, '===========================')
      viewer?.imageryLayers.remove(tdtStand_c)
      viewer?.imageryLayers.remove(tdtStand_zj)
    }
@@ -258,6 +274,8 @@
    zoonIn,
    zoonOut,
    roadPattern,
    patternMap
    patternMap,
    getEntityById,
    updateEntityPosition
  }
}