From a0f008e1b176ab0c844bc4721f282e12d18f855c Mon Sep 17 00:00:00 2001
From: chenyao <1219716595@qq.com>
Date: Mon, 24 Feb 2025 18:20:11 +0800
Subject: [PATCH] 调整详情和修改地图渲染功能

---
 src/views/hooks/droneFly.ts |  393 ++++++++++++++++----------------------------------------
 1 files changed, 113 insertions(+), 280 deletions(-)

diff --git a/src/views/hooks/droneFly.ts b/src/views/hooks/droneFly.ts
index 6fa5560..a42f788 100644
--- a/src/views/hooks/droneFly.ts
+++ b/src/views/hooks/droneFly.ts
@@ -36,16 +36,17 @@
   let viewInfoFrustum = null
 
   // 手机设备定位
-  let me_latitude = 0;
-  let me_longitude = 0;
+  let me_latitude = 0;// 28.624647955787974;
+  let me_longitude = 0;//115.85635808986208;
   let me_altitude = 0;
   // 扫射定位
-  let measure_target_longitude = 0;
-  let measure_target_latitude = 0;
+  let measure_target_longitude = 0;//115.85635872364763;
+  let measure_target_latitude = 0;//28.624648387113627;
   let measure_target_altitude = 0;
 
 
   async function initDock(data:any, sn:any, dockSn:any, workspaceId:any, ssLinePath:any, viewDroneInfo:any) {
+    // console.log('globalCesium查看是', globalCesium)
     // 获取workspaceId
     wId = workspaceId
     // 给无人机参数赋值
@@ -53,7 +54,6 @@
     // 机场信息
     dockInfo = data.dockInfo[`${dockSn}`]
     viewDroneInfo = viewDroneInfo
-    console.log('导致地图不显示原因1',viewDroneInfo.longitude)
     // 当前飞行任务创建时间
     if (data.currentType === EDeviceTypeName.Aircraft && deviceInfo) {
       const droneLngLat = {
@@ -67,6 +67,7 @@
           if (store.currentAngle == 3) {
             viewInfoFrustum?.clear()
           } else {
+            // 暂时把视锥代码注释掉
             initCreateFrustum(deviceInfo, viewDroneInfo)
           }
           addFlyGltf(
@@ -105,6 +106,7 @@
         }
       } else {
         if (deviceInfo.mode_code && [3, 4, 5, 9, 10].includes(deviceInfo.mode_code)) {
+          // 暂时把视锥代码注释掉
           initCreateFrustum(deviceInfo, viewDroneInfo)
           addFlyGltf(
             viewDroneInfo.longitude,
@@ -125,68 +127,68 @@
         }
       }
       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,
-          },
-        })
-      }
+      // 暂时把航线屏蔽
+      // 无人机路线轨迹,判断是否存在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 (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)
+      //     // 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.currentType === EDeviceTypeName.Dock && data.dockInfo[data.currentSn]) {
       if (!deviceInfo?.basic_osd?.longitude || !deviceInfo?.basic_osd?.latitude) return
-      console.log('6666', deviceInfo?.basic_osd?.longitude)
       if (snCode.includes(data.currentSn)) return
       snCode.push(data.currentSn)
     }
@@ -195,6 +197,8 @@
   const imgLaser = new URL('@/assets/images/laser.png', import.meta.url).href
   // 增加激光扫射点
   function addFlyLaser(payloads:any) {
+    console.log('激光扫射经度',payloads.measure_target_longitude)
+    console.log('激光扫射纬度',payloads.measure_target_latitude)
     const startPosition = globalCesium.Cartesian3.fromDegrees(
       me_longitude, me_latitude, 0
     )
@@ -205,57 +209,59 @@
     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)
+    // 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
+    //   laserEntity.show = true
   
-      window.cesiumViewer.scene.requestRender()
-    } else {
+    //   window.cesiumViewer.scene.requestRender()
+    // } else {
+      removeById('laser_coordinate')
       laserEntity = window.cesiumViewer.entities.add({
-        position,
+        position: globalCesium.Cartesian3.fromDegrees(payloads.measure_target_longitude, payloads.measure_target_latitude, payloads.measure_target_altitude),
         id: 'laser_coordinate',
         billboard: {
           image: imgLaser,
-          outlineWidth: 0,
-          width: 36,
-          height: 36,
+          width: 30,
+          height: 30,
           scale: 1.0,
+          outlineWidth: 0,
         }
       })
-    }
-    removeById('route_two_line')
-    twoLineEntity = window.cesiumViewer.entities.add({
-      id: 'route_two_line',
-      polyline: {
-        positions: new globalCesium.CallbackProperty(() => [startPosition, position], false),
-        width: 5,
-        material: new globalCesium.PolylineDashMaterialProperty({
-            color: globalCesium.Color.YELLOW, // 虚线颜色
-            dashLength: 6.0, // 虚线段的长度
-        }),
-        zIndex: 1,
-        clampToGround: false,
-      }
-    })
+    // }
     // 增加激光扫射信息
     laserEntity.label = new globalCesium.LabelGraphics({
-      text: `目标海拔:${Math.ceil(payloads.measure_target_altitude)}m\n测距距离:${Math.round(
-        Math.ceil(payloads.measure_target_distance),
-      )}m`,
+      text: `H:${Math.ceil(payloads.measure_target_altitude)}m-L:${Math.round(Math.ceil(payloads.measure_target_distance),)}m`,
       font: '13px monospace',
+      fillColor: globalCesium.Color.fromCssColorString('red'), // 文字颜色
+      backgroundColor: globalCesium.Color.WHITE, // 背景颜色
       showBackground: true,
       horizontalOrigin: globalCesium.HorizontalOrigin.CENTER,
       verticalOrigin: globalCesium.VerticalOrigin.BOTTOM,
       disableDepthTestDistance: Number.POSITIVE_INFINITY,
-      pixelOffset: new globalCesium.Cartesian2(0, -40),
+      pixelOffset: new globalCesium.Cartesian2(0, -20),
       show: true,
     })
+    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,
+        }
+      })
+    }
   }
 
   function addFlyGltf (lng:any, lat:any, alt:any, payloads:any, attitude_head:any, deviceInfo:any, dockInfo:any, ssLinePath:any) {
@@ -306,179 +312,7 @@
     }
   
     // 创建无人机信息
-    createDroneEntityLabel(droneEntity, deviceInfo, dockInfo, ssLinePath)
-  }
-  // 创建无人机信息
-  async function createDroneEntityLabel (entity:any, deviceInfo:any, dockInfo:any, ssLinePath:any) {
-    deviceInfo = deviceInfo
-    if (currentTaskCreateTime === null) return
-    if (!deviceInfo?.longitude && !deviceInfo?.latitude) return
-    if (deviceInfo.mode_code !== 5) {
-      currentTaskCreateTime = null
-      return
-    }
-    const executingWayline = store.executingWayline
-    if (!executingWayline?.id) return
-    if (waylinePoints.length === 0) {
-      // 改成获取航线地址
-      // const routeRes = await getRoutePlanningUrl(
-      //   wId,
-      //   executingWayline.id,
-      // )
-      // const routeData = routeRes.data
-      // if (routeData.code !== 0) return this.$message.error('获取航线信息失败!')
-      waylinePoints = await getWaylineFilePoints(ssLinePath)
-    }
-
-    const nextPoint = waylinePoints[currentWaypointIndex]
-    if (!nextPoint) return
-    // 两点之间的距离
-    console.log('8888', deviceInfo.longitude)
-    const devicePosition = globalCesium.Cartesian3.fromDegrees(
-      Number(deviceInfo.longitude),
-      Number(deviceInfo.latitude),
-      0,
-    )
-    console.log('9999', nextPoint.longitude)
-    const targetPosition = globalCesium.Cartesian3.fromDegrees(
-      Number(nextPoint.longitude),
-      Number(nextPoint.latitude),
-      0,
-    )
-    //   距离下个点位的距离
-    let distance = globalCesium.Cartesian3.distance(
-      devicePosition,
-      targetPosition,
-    )
-    const dockPosition = {
-      longitude: dockInfo?.basic_osd?.longitude,
-      latitude: dockInfo?.basic_osd?.latitude,
-    }
-
-    const distArr = waylinePoints.map((lnglat, index) => {
-      const { longitude, latitude } = lnglat
-      console.log('10000', longitude)
-      // 两点之间的距离
-      let devicePosition = null
-      if (index === 0) {
-        devicePosition = globalCesium.Cartesian3.fromDegrees(
-          Number(dockPosition.longitude),
-          Number(dockPosition.latitude),
-          0,
-        )
-      } else {
-        console.log('110', prevPoint.longitude)
-        const prevPoint = waylinePoints[index - 1]
-        devicePosition = globalCesium.Cartesian3.fromDegrees(
-          Number(prevPoint.longitude),
-          Number(prevPoint.latitude),
-          0,
-        )
-      }
-      const targetPosition = globalCesium.Cartesian3.fromDegrees(
-        Number(longitude),
-        Number(latitude),
-        0,
-      )
-      let distance = globalCesium.Cartesian3.distance(
-        devicePosition,
-        targetPosition,
-      )
-      return Math.round(distance)
-    })
-    // 计算到达点位和之前点位的总距离
-    let sum = null
-    if (distArr.length > 2) {
-      sum = distArr
-        .slice(0, currentWaypointIndex)
-        .reduce((accumulator, currentValue) => accumulator + currentValue, 0)
-    } else {
-      sum = distArr.reduce(
-        (accumulator, currentValue) => accumulator + currentValue,
-        0,
-      )
-    }
-
-    if (sum == 0) {
-      sum = distArr[0]
-    }
-
-    // 距离机场的位置
-    const homeDistance = Math.floor(deviceInfo.home_distance) || 0
-    // 速度
-    let horizontalSpeed = deviceInfo.horizontal_speed || 0
-    if (!droneSpeedArr.includes(horizontalSpeed) && horizontalSpeed > 1) {
-      droneSpeedArr.push(horizontalSpeed)
-    }
-    //  平均速度
-    const averageSpeed =
-      droneSpeedArr.reduce((sum, current) => sum + current, 0) /
-      droneSpeedArr.length
-    // 已用时间
-    let usedTime = Math.round((new Date().getTime() - currentTaskCreateTime) / 1000) - 30
-    let throughDistance = usedTime * averageSpeed
-
-    if (throughDistance < 0) {
-      throughDistance = 0
-      usedTime = 0
-    }
-    if (isNaN(throughDistance)) {
-      throughDistance = 0
-    }
-    if (isNaN(usedTime)) {
-      usedTime = 0
-    }
-    if (usedTime > 60) {
-      const minute = Math.floor(usedTime / 60)
-      const second = Math.round(usedTime % 60)
-      usedTime = `${minute}m${second}s`
-    } else {
-      usedTime = Math.round(usedTime) + 's'
-    }
-
-    if (horizontalSpeed < 5) {
-      horizontalSpeed = 10
-    }
-    // 预计到达下一个航点时间
-    let arrivalTime = distance / horizontalSpeed
-    if (arrivalTime === Infinity || isNaN(arrivalTime)) {
-      arrivalTime = 0
-    }
-    if (arrivalTime > 60) {
-      const minute = Math.floor(arrivalTime / 60)
-      const second = Math.round(arrivalTime % 60)
-      arrivalTime = `${minute}m${second}s`
-    } else {
-      arrivalTime = Math.round(arrivalTime) + 's'
-    }
-    entity.label = new globalCesium.LabelGraphics({
-      text: `距离机场水平距离:${homeDistance}m\n距离下一个航点:${Math.round(
-        distance,
-      )}m\n预计到达下一航点时间:${arrivalTime}\n本次飞行时间:${usedTime}\n本次航线平面里程:${Math.round(
-        throughDistance,
-      )}m`,
-      font: '13px monospace',
-      showBackground: true,
-      horizontalOrigin: globalCesium.HorizontalOrigin.CENTER,
-      verticalOrigin: globalCesium.VerticalOrigin.BOTTOM,
-      disableDepthTestDistance: Number.POSITIVE_INFINITY,
-      pixelOffset: new globalCesium.Cartesian2(0, -40),
-      show: true,
-    })
-  }
-  async function getWaylineFilePoints(fileUrl:any) {
-    const fileRes = await analyzeKmzFile(fileUrl);
-    const waylineContent = await fileRes['fileInfoObj']?.['wpmz/waylines.wpml'];
-    const xml = XMLToJSON(waylineContent);
-    const placemarkArr = xml?.Document?.Folder.Placemark;
-    const points = placemarkArr.map((placemark) => {
-      const lnglat = placemark.Point.coordinates?.['#text'].split(',');
-      return {
-        longitude: lnglat[0],
-        latitude: lnglat[1],
-      };
-    });
-    return points;
+    // createDroneEntityLabel(droneEntity, deviceInfo, dockInfo, ssLinePath)
   }
 
   function setelCamera (lng, lat, alt, payloads, attitude_head) {
@@ -539,8 +373,9 @@
   }
   // 创建视锥
   function initCreateFrustum (deviceInfo:any, test:any) {
-    
-    if (!deviceInfo || !deviceInfo.longitude || !deviceInfo.latitude) return
+    // console.log('视锥传参1',deviceInfo)
+    // console.log('视锥传参2',test)
+    if (!deviceInfo || !deviceInfo.longitude || !deviceInfo.latitude || !test.longitude || !test.latitude) return
     
     const attitude_head = 180 + deviceInfo.attitude_head
 
@@ -566,26 +401,21 @@
 
   // 获取手机定位和激光发射定位的高度和距离
   function getTwoHeightWidth(workspaceId:String) {
-    // 国内地图不会为0或者小于0
-    console.log('自身定位经纬度1', me_latitude)
-    console.log('自身定位经纬度2', me_longitude)
-    console.log('激光扫过定位1', measure_target_latitude)
-    console.log('激光扫过定位2', measure_target_longitude)
     if (me_latitude <= 0 || me_longitude <= 0 || measure_target_latitude <= 0 || measure_target_longitude <= 0) return
     getTwoPointInfo(workspaceId,me_latitude,me_longitude,measure_target_latitude,measure_target_longitude).then((res:any) => {
       const heightDifference = res.data.heightDifference
       const distance = res.data.distance
       // 增加激光扫射信息
       myAppEntity.label = new globalCesium.LabelGraphics({
-        text: `高度:${Math.ceil(heightDifference)}m\n距离:${Math.round(
-          Math.ceil(distance),
-        )}m`,
+        text: `H:${Math.ceil(heightDifference)}m-L:${Math.round(Math.ceil(distance),)}m`,
         font: '13px monospace',
+        fillColor: globalCesium.Color.fromCssColorString('red'), // 文字颜色
+        backgroundColor: globalCesium.Color.WHITE, // 背景颜色
         showBackground: true,
         horizontalOrigin: globalCesium.HorizontalOrigin.CENTER,
         verticalOrigin: globalCesium.VerticalOrigin.BOTTOM,
         disableDepthTestDistance: Number.POSITIVE_INFINITY,
-        pixelOffset: new globalCesium.Cartesian2(0, -40),
+        pixelOffset: new globalCesium.Cartesian2(0, -24),
         show: true,
       })
     })
@@ -597,6 +427,8 @@
     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;
@@ -611,6 +443,7 @@
             width: 30,
             height: 30,
             scale: 1.0,
+            outlineWidth: 0,
           }
         });
         // 查看两条线直接距离和高度

--
Gitblit v1.9.3