forked from drone/command-center-dashboard

shuishen
2025-04-19 46fade7760ade1b94c8cfd653942756dabb7ccea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as Cesium from 'cesium'
import aircraftGltf from '@/assets/gltf/aircraft.gltf'
import CreateFrustum from '@/utils/cesium/frustum/CreateFrustum'
 
export function useTaskViewInfo (viewer, wsInfo) {
  const newViewer = isRef(viewer) ? viewer : ref(viewer)
 
  let viewInfoFrustum
  // 设置视椎
  const setCreateFrustum = (host) => {
    if (!host) return
    viewInfoFrustum?.clear()
 
    const attitude_head = 180 + host.attitude_head
    const gimbal_pitch = 90 - Number(host?.payloads[0]?.gimbal_pitch) || 0
 
    viewInfoFrustum = new CreateFrustum(newViewer.value, {
      position: {
        longitude: host.longitude,
        latitude: host.latitude,
        altitude: host.height,
      },
      width: 30,
      height: 30,
      fov: 20.0,
      near: 3.0,
      far: 250.0,
      roll: gimbal_pitch,
      pitch: 0,
      heading: attitude_head,
    })
  }
 
  function setAircraftGltf () {
    const host = deviceOsdInfo.value?.data?.host
    const aircraftEntity = newViewer.value?.entities.getById('aircraftGltf')
    const position = Cesium.Cartesian3.fromDegrees(host.longitude, host.latitude, host.height)
    if (aircraftEntity) {
      aircraftEntity.position = new Cesium.ConstantPositionProperty(position)
      return
    }
 
    newViewer.value?.entities.add({
      id: 'aircraftGltf',
      position,
      model: {
        uri: aircraftGltf, // 或 .glb
        scale: 1.0, // 缩放比例
        minimumPixelSize: 64, // 最小像素尺寸(保证模型远处可见)
        maximumScale: 128, // 最大缩放(可选)
      },
    })
  }
 
  // 视椎加载处理
  const deviceOsdInfo = computed(() => wsInfo.value?.device_osd)
 
 
  watch(
    [
      () => deviceOsdInfo.value,
      () => newViewer.value
    ],
    (
      [curDeviceOsdInfo, curViewer],
    ) => {
      const host = deviceOsdInfo.value?.data?.host
 
      if (!curViewer) return
 
      if ([14, 0].includes(host.mode_code)) {
        mapEntityRemove()
        return
      }
 
      setCreateFrustum(host)
      setAircraftGltf()
    }
  )
 
  const mapEntityRemove = () => {
    viewInfoFrustum?.clear()
 
    newViewer.value?.entities.removeById('aircraftGltf')
  }
 
  onUnmounted(() => {
    mapEntityRemove()
  })
}