From 4ff3eee77b41466d08117970970d01be6e48ffe1 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Fri, 28 Mar 2025 19:02:30 +0800
Subject: [PATCH] Merge branch 'master' of http://139.196.74.78:10010/r/drone/pilot-h5

---
 src/views/hooks/droneFly.ts |  249 ++++++++++++++++++++++++++++---------------------
 1 files changed, 140 insertions(+), 109 deletions(-)

diff --git a/src/views/hooks/droneFly.ts b/src/views/hooks/droneFly.ts
index a42f788..3cfebf3 100644
--- a/src/views/hooks/droneFly.ts
+++ b/src/views/hooks/droneFly.ts
@@ -7,7 +7,7 @@
 import { useMyStore } from '@/store'
 import { getTwoPointInfo } from '@/api/manage'
 
-const { getEntityById, removeById, globalCesium, addLeftClickEvent, removeLeftClickEvent, flyTo } = cesiumOperation()
+const { getEntityById, removeById, globalCesium, removeAllPoint, addLeftClickEvent, removeLeftClickEvent, flyTo } = cesiumOperation()
 // 无人机实体
 let droneEntity = null
 
@@ -45,8 +45,7 @@
   let measure_target_altitude = 0;
 
 
-  async function initDock(data:any, sn:any, dockSn:any, workspaceId:any, ssLinePath:any, viewDroneInfo:any) {
-    // console.log('globalCesium查看是', globalCesium)
+  async function initDock(data:any, sn:String, dockSn:String, workspaceId:String, ssLinePath:String, viewDroneInfo:any) {
     // 获取workspaceId
     wId = workspaceId
     // 给无人机参数赋值
@@ -63,7 +62,7 @@
       // 当飞机模型存在
       if (droneEntity) {
         //  且在空中飞行时,实时更新飞机模型的位置
-        if (deviceInfo.mode_code && [3, 4, 5, 9, 10, 16].includes(deviceInfo.mode_code)) {
+        if (deviceInfo.mode_code && [3, 4, 5, 9, 10, 16, 17].includes(deviceInfo.mode_code)) {
           if (store.currentAngle == 3) {
             viewInfoFrustum?.clear()
           } else {
@@ -81,11 +80,11 @@
             ssLinePath
           )
           let domain = sessionStorage.getItem('domain')
-          if (domain !== '0') {
-            addFlyLaser(
-              deviceInfo.payloads[0]
-            )
-          }
+          // if (domain !== '0') {
+          //   addFlyLaser(
+          //     deviceInfo.payloads[0]
+          //   )
+          // }
           setelCamera(
             viewDroneInfo.longitude,
             viewDroneInfo.latitude,
@@ -96,6 +95,9 @@
         } else {
           removeById('drone_fly')
           droneEntity = null
+
+          removeById('me_dw')
+          myAppEntity = null
   
           lastTime = null
           viewInfoFrustum?.clear()
@@ -103,10 +105,10 @@
   
           window.cesiumViewer.camera.lookAtTransform(globalCesium.Matrix4.IDENTITY)
           store.commit('SET_CURRENTANGLE', 1)
+          removeAllPoint()
         }
       } else {
-        if (deviceInfo.mode_code && [3, 4, 5, 9, 10].includes(deviceInfo.mode_code)) {
-          // 暂时把视锥代码注释掉
+        if (deviceInfo.mode_code && [3, 4, 5, 9, 10, 17].includes(deviceInfo.mode_code)) {
           initCreateFrustum(deviceInfo, viewDroneInfo)
           addFlyGltf(
             viewDroneInfo.longitude,
@@ -119,73 +121,71 @@
             ssLinePath
           )
           let domain = sessionStorage.getItem('domain')
-          if (domain !== '0') {
-            addFlyLaser(
-              deviceInfo.payloads[0]
-            )
-          }
+          // if (domain !== '0') {
+          //   addFlyLaser(
+          //     deviceInfo.payloads[0]
+          //   )
+          // }
         }
       }
       const imgRightBlue = new URL('@/assets/images/arrow-right-pink.png', import.meta.url).href
-      // 暂时把航线屏蔽
       // 无人机路线轨迹,判断是否存在drone_route_remove
-      // if (getEntityById('drone_route_remove')) {
-      //   window.cesiumViewer.entities.add({
-      //     name: 'drone_route_remove',
-      //     id: 'drone_route_remove',
-      //     polyline: {
-      //       width: 7,
-      //       positions: previousPositions,
-      //       material: new ImageTrailMaterial({
-      //         color: globalCesium.Color.ORANGE,
-      //         speed: 10,
-      //         image: imgRightBlue,
-      //         repeat: { x: 1, y: 0 },
-      //       }),
-      //       clampToGround: false,
-      //     },
-      //   })
-      // }
+      if (getEntityById('drone_route_remove')) {
+        window.cesiumViewer.entities.add({
+          name: 'drone_route_remove',
+          id: 'drone_route_remove',
+          polyline: {
+            width: 7,
+            positions: previousPositions,
+            material: new ImageTrailMaterial({
+              color: globalCesium.Color.ORANGE,
+              speed: 10,
+              image: imgRightBlue,
+              repeat: { x: 1, y: 0 },
+            }),
+            clampToGround: false,
+          },
+        })
+      }
       
-      // if (data.deviceInfo[data.currentSn].mode_code && [3, 4, 5, 9, 10].includes(deviceInfo.mode_code)) {
-      //   if (switchSaving) return (switchSaving = false)
-      //     // console.log('5555', data.deviceInfo[data.currentSn].longitude)
-      //   const newPositions = globalCesium.Cartesian3.fromDegrees(
-      //     data.deviceInfo[data.currentSn].longitude,
-      //     data.deviceInfo[data.currentSn].latitude,
-      //     Math.floor(viewDroneInfo.elevation),
-      //   )
-      //   //若刷新,恢复无人机之前的路线轨迹
-      //   const dataIndexedDB = await IndexedDBService.getDataById(wId)
-      //   if (previousPositions.length == 0 && dataIndexedDB) {
-      //     previousPositions = previousPositions.concat(dataIndexedDB?.temporaryflightData)
-      //   } else {
-      //     previousPositions = previousPositions.concat(newPositions)
-      //   }
-      //   // 保存无人机当前执行的路线,防止刷新数据丢失
-      //   if (!dataIndexedDB) {
-      //     await IndexedDBService.addData({
-      //       id: wId,
-      //       temporaryflightData: previousPositions,
-      //     })
-      //   } else {
-      //     await IndexedDBService.updateData(wId, {temporaryflightData: previousPositions})
-      //   }
-      //   //  更新线段的位置
-      //   const drone_route_remove = getEntityById('drone_route_remove')
-      //   if (!drone_route_remove) return
-      //   drone_route_remove.polyline.positions = previousPositions
-      //   drone_route_remove.polyline._material._repeat._value.x = Math.floor(previousPositions.length / 7)
-      // } else if ([0, 14].includes(deviceInfo.mode_code)) {
-      //   previousPositions = []
-      //   await IndexedDBService.deleteData(wId)
-      //   const drone_route_remove = getEntityById('drone_route_remove')
-      //   if (!drone_route_remove) return
-      //   drone_route_remove.polyline.positions = previousPositions
-      //   removeById('drone_route_remove')
-      //   viewInfoFrustum?.clear()
-      //   viewInfoFrustum = null
-      // }
+      if (data.deviceInfo[data.currentSn].mode_code && [3, 4, 5, 9, 10].includes(deviceInfo.mode_code)) {
+        if (switchSaving) return (switchSaving = false)
+        const newPositions = globalCesium.Cartesian3.fromDegrees(
+          data.deviceInfo[data.currentSn].longitude,
+          data.deviceInfo[data.currentSn].latitude,
+          Math.floor(viewDroneInfo.elevation),
+        )
+        //若刷新,恢复无人机之前的路线轨迹
+        const dataIndexedDB = await IndexedDBService.getDataById(wId)
+        if (previousPositions.length == 0 && dataIndexedDB) {
+          previousPositions = previousPositions.concat(dataIndexedDB?.temporaryflightData)
+        } else {
+          previousPositions = previousPositions.concat(newPositions)
+        }
+        // 保存无人机当前执行的路线,防止刷新数据丢失
+        if (!dataIndexedDB) {
+          await IndexedDBService.addData({
+            id: wId,
+            temporaryflightData: previousPositions,
+          })
+        } else {
+          await IndexedDBService.updateData(wId, {temporaryflightData: previousPositions})
+        }
+        //  更新线段的位置
+        const drone_route_remove = getEntityById('drone_route_remove')
+        if (!drone_route_remove) return
+        drone_route_remove.polyline.positions = previousPositions
+        drone_route_remove.polyline._material._repeat._value.x = Math.floor(previousPositions.length / 7)
+      } else if ([0, 14].includes(deviceInfo.mode_code)) {
+        previousPositions = []
+        await IndexedDBService.deleteData(wId)
+        const drone_route_remove = getEntityById('drone_route_remove')
+        if (!drone_route_remove) return
+        drone_route_remove.polyline.positions = previousPositions
+        removeById('drone_route_remove')
+        viewInfoFrustum?.clear()
+        viewInfoFrustum = null
+      }
     }
     if (data.currentType === EDeviceTypeName.Dock && data.dockInfo[data.currentSn]) {
       if (!deviceInfo?.basic_osd?.longitude || !deviceInfo?.basic_osd?.latitude) return
@@ -209,21 +209,23 @@
     measure_target_latitude = payloads.measure_target_latitude;
     measure_target_altitude = payloads.measure_target_altitude;
 
-    // if (laserEntity && laserEntity != null) {
-    //   laserEntity.position = new globalCesium.CallbackProperty(function () {
-    //     return position
-    //   }, false)
-    //   // laserEntity.orientation = new globalCesium.CallbackProperty(function () {
-    //   //   return orientation
-    //   // }, false)
-  
-    //   laserEntity.show = true
-  
-    //   window.cesiumViewer.scene.requestRender()
-    // } else {
+    if (laserEntity && laserEntity != null) {
+      laserEntity.position = new globalCesium.CallbackProperty(function () {
+        return position
+      }, false)
+      
+      laserEntity.show = true
+      window.cesiumViewer.scene.requestRender()
+    } else {
       removeById('laser_coordinate')
       laserEntity = window.cesiumViewer.entities.add({
-        position: globalCesium.Cartesian3.fromDegrees(payloads.measure_target_longitude, payloads.measure_target_latitude, payloads.measure_target_altitude),
+        position: new globalCesium.CallbackProperty(() => {
+          return globalCesium.Cartesian3.fromDegrees(
+            payloads.measure_target_longitude, 
+            payloads.measure_target_latitude, 
+            payloads.measure_target_altitude
+          )
+        }, false),
         id: 'laser_coordinate',
         billboard: {
           image: imgLaser,
@@ -233,7 +235,7 @@
           outlineWidth: 0,
         }
       })
-    // }
+    }
     // 增加激光扫射信息
     laserEntity.label = new globalCesium.LabelGraphics({
       text: `H:${Math.ceil(payloads.measure_target_altitude)}m-L:${Math.round(Math.ceil(payloads.measure_target_distance),)}m`,
@@ -250,17 +252,38 @@
     console.log('起点',startPosition)
     console.log('终点',position)
     if (startPosition && position) {
-      removeById('route_two_line')
-      twoLineEntity = window.cesiumViewer.entities.add({
-        id: 'route_two_line',
-        polyline: {
-          positions: new globalCesium.CallbackProperty(() => [startPosition, position], false),
-          width: 3,
-          material: globalCesium.Color.RED,
-          zIndex: -1,
-          clampToGround: false,
-        }
-      })
+      if (twoLineEntity && twoLineEntity != null) {
+        // 如果线实体已存在,只更新位置
+        twoLineEntity.polyline.positions = new globalCesium.CallbackProperty(() => {
+          return [
+            globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, 0),
+            globalCesium.Cartesian3.fromDegrees(
+              payloads.measure_target_longitude,
+              payloads.measure_target_latitude,
+              payloads.measure_target_altitude
+            )
+          ]
+        }, false)
+      } else {
+        // 如果线实体不存在,创建新的线实体
+        twoLineEntity = window.cesiumViewer.entities.add({
+          polyline: {
+            positions: new globalCesium.CallbackProperty(() => {
+              return [
+                globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, 0),
+                globalCesium.Cartesian3.fromDegrees(
+                  payloads.measure_target_longitude,
+                  payloads.measure_target_latitude,
+                  payloads.measure_target_altitude
+                )
+              ]
+            }, false),
+            width: 2,
+            material: globalCesium.Color.fromCssColorString('red'),
+            clampToGround: false,
+          },
+        })
+      }
     }
   }
 
@@ -426,26 +449,34 @@
   function getPhoneLocation(workspaceId:String) {
     if (window.cesiumViewer == null) return
     if (navigator.geolocation) {
-      navigator.geolocation.watchPosition((position) => {
-        console.log(me_longitude,position.coords.longitude)
-        console.log(me_latitude,position.coords.latitude)
-        if (me_longitude > 0 && me_longitude == position.coords.longitude && me_latitude > 0 && me_latitude == position.coords.latitude) return 
-        me_longitude = position.coords.longitude;
-        me_latitude = position.coords.latitude;
-        me_altitude = position.coords.altitude || 0;
-        // 创建一个箭头实体
-        removeById('me_dw')
+      // 如果实体不存在,先创建实体
+      if (!myAppEntity) {
         myAppEntity = window.cesiumViewer.entities.add({
           id: 'me_dw',
-          position: globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, me_altitude),
+          position: new globalCesium.CallbackProperty(() => {
+            return globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, me_altitude)
+          }, false),
           billboard: {
-            image: meMapSrc, // 箭头图片路径
+            image: meMapSrc,
             width: 30,
             height: 30,
             scale: 1.0,
             outlineWidth: 0,
           }
         });
+      } else {
+        myAppEntity.position = new globalCesium.CallbackProperty(() => {
+          return globalCesium.Cartesian3.fromDegrees(me_longitude, me_latitude, me_altitude)
+        }, false);
+      }
+      navigator.geolocation.watchPosition((position) => {
+        if (me_longitude > 0 && me_longitude == position.coords.longitude && 
+            me_latitude > 0 && me_latitude == position.coords.latitude) return 
+        
+        me_longitude = position.coords.longitude;
+        me_latitude = position.coords.latitude;
+        me_altitude = position.coords.altitude || 0;
+        
         // 查看两条线直接距离和高度
         getTwoHeightWidth(workspaceId)
       }, (error) => {

--
Gitblit v1.9.3