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 |  137 ++++++++++++++++++++++++++++-----------------
 1 files changed, 85 insertions(+), 52 deletions(-)

diff --git a/src/views/hooks/droneFly.ts b/src/views/hooks/droneFly.ts
index f75d3b7..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,11 +121,11 @@
             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
@@ -207,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,
@@ -231,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`,
@@ -248,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,
+          },
+        })
+      }
     }
   }
 
@@ -424,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