From afec9f1c12683a11845b277c62e0ca9b83e1a5ca Mon Sep 17 00:00:00 2001
From: jihongshun <1151753686@qq.com>
Date: 星期四, 07 八月 2025 15:38:23 +0800
Subject: [PATCH] 切换设备正反逻辑

---
 src/views/system/project/components/addPorjectDialog.vue |  276 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 231 insertions(+), 45 deletions(-)

diff --git a/src/views/system/project/components/addPorjectDialog.vue b/src/views/system/project/components/addPorjectDialog.vue
index 89e5cc5..9a082c5 100644
--- a/src/views/system/project/components/addPorjectDialog.vue
+++ b/src/views/system/project/components/addPorjectDialog.vue
@@ -15,6 +15,7 @@
                   <el-table
                     :data="tableData"
                     max-height = '180'
+                    :row-key="getRowKeys"
                     style="width: 100%">
                     <el-table-column
                       prop="deviceName"
@@ -45,6 +46,7 @@
                   <div class="fontJust">宸℃鐐圭洰褰�</div>
                   <el-tree
                     class="filter-tree"
+                    node-key="id"
                     :data="treeData"
                     :props="defaultProps"
                     default-expand-all
@@ -70,8 +72,9 @@
 import CesiumMap from "../../../../utils/components/cesium-map.vue";
 import chooseDeviceDialog from './chooseDeviceDialog.vue';
 import chooseModelDialog from './chooseModelDialog.vue';
-import { obtainRealData} from "@/api/system/template"
-
+import { obtainRealData ,buildKmz} from "@/api/system/template"
+let rotationAngle = Cesium.Math.toRadians(0)
+let lastConnectPolyline 
 export  default{
   components: {
     CesiumMap,
@@ -99,9 +102,9 @@
       this.$emit('close')
     },
     flyToLocal(row){
-      console.log(row)
-       const position = Cesium.Cartesian3.fromDegrees(row.longitude,row.latitude, row.altitude);
-
+       const position = Cesium.Cartesian3.fromDegrees(row.longitude,row.latitude, row.deviceHeight);
+      // rotationAngle  = Cesium.Math.toRadians(row.face)  ||  Cesium.Math.toRadians(0)
+      rotationAngle  = Cesium.Math.toRadians(row.face)  ||  Cesium.Math.toRadians(0)
       // 璁剧疆妯″瀷鏂瑰悜锛堝彲閫夛級
       const heading = Cesium.Math.toRadians(row.face); // 鏈濅笢鍗楁柟鍚�
       const pitch = 0;
@@ -178,14 +181,60 @@
       }));
     },
     deleteData(row){
+      console.log(row)
       // 鎵惧埌 id 涓� "1" 鐨勫厓绱犵储寮�
       const index = this.tableData.findIndex(item => item.id === row.id);
       // 濡傛灉鎵惧埌浜嗭紝鍒犻櫎璇ュ厓绱�
       if (index !== -1) {
         this.tableData.splice(index, 1);
       }
-      const dealTreeData = this.dealTee()
-      this.treeData = dealTreeData
+      const indexTree = this.treeData.findIndex(item => item.id === row.id);
+      // 濡傛灉鎵惧埌浜嗭紝鍒犻櫎璇ュ厓绱�
+      if (index !== -1) {
+        this.treeData.splice(indexTree, 1);
+      }
+      if(this.treeData?.length >=2 && this.treeData[0]?.children?.length > 0 && this.treeData[1]?.children?.length > 0 ) {
+          this.dealAddHeight()
+      } else if(this.treeData?.length ==1) {
+        this.treeData.map((device,index) => {
+          // 纭繚璁惧鏈塩hildren鏁扮粍
+          if(index == 0) {
+            //绗竴涓暟鎹�
+            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
+                // 鑾峰彇鏈�鍚庝竴涓┖涓偣
+                const lastChild = device.children[device.children.length - 1];
+                const firstChild = device.children[0];
+                // 娣辨嫹璐濇渶鍚庝竴涓厓绱狅紙鍖呮嫭宓屽鐨刢hildren锛�
+                const newChildJson = JSON.parse(JSON.stringify(lastChild));
+                // 娣辨嫹璐濇渶涓�涓�涓厓绱狅紙鍖呮嫭宓屽鐨刢hildren锛�
+                const firstChildJson = JSON.parse(JSON.stringify(firstChild));
+
+                if(newChildJson && newChildJson.label.includes('鍔犻珮')){
+                  device.children?.pop(newChild);
+                }else if(firstChildJson && firstChildJson.label.includes('鍔犻珮')) {
+                    device.children?.shift(firstChildJson);
+                }
+                // 娣诲姞鍒癱hildren鏁扮粍鏈熬
+            }
+          }
+        })
+      }
+      const entitiesToRemove = [];
+      viewer.entities.values.forEach(entity => {
+        if (entity.id && entity.id.includes(row.id)) {
+          entitiesToRemove.push(entity.id);
+        }
+      });
+      entitiesToRemove.forEach(id => {
+        viewer.entities.removeById(id);
+      });
+      this.drawConnectionsWithLabels(this.treeData)
+      // console.log(this.tableData)
+      console.log(this.treeData)
+      // const dealTreeData = this.dealTee()
+      // console.log(dealTreeData)
+      // this.treeData = dealTreeData
+      // this.drawConnectionsWithLabels(this.treeData)
     },
     chooseModel(row){
       this.deviceId = row.id
@@ -196,7 +245,6 @@
     },
     receiveModel(obj){
       //deal閫昏緫
-      console.log(obj)
       let flightTemplateId =obj.modelObj.id
       let deviceId = obj.deviceId
       this.dealTableTemplate(obj)
@@ -206,13 +254,87 @@
         let treeDealData = this.transformFlightData(res.data?.coordinateSystemVoS || [])
         console.log(treeDealData)
         this.dealTreeMerge(obj,treeDealData)
-        // const aaa = this.rotateAllPoints(this.treeData || [],res.data.longitude,res.data.latitude,res.data.height)
-         this.drawConnectionsWithLabels(this.treeData)
+        
+        this.rotateAllPoints(this.treeData || [],res.data.longitude,res.data.latitude,res.data.height)
+        console.log(this.treeData)
+        if(this.treeData?.length >=2 && this.treeData[0]?.children?.length > 0 && this.treeData[1]?.children?.length > 0 ) {
+            this.dealAddHeight()
+        }
+        console.log(this.treeData)
+        this.drawConnectionsWithLabels(this.treeData)
       })
       // this.dealTreeMerge(obj)
     },
+    dealAddHeight(){
+      let currentLength = this.treeData.filter(item=>item.children)?.length || 0
+      console.log(this.treeData)
+      console.log(currentLength)
+      this.treeData.map((device,index) => {
+          // 纭繚璁惧鏈塩hildren鏁扮粍
+          if(index == 0) {
+            //绗竴涓暟鎹�
+            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
+                // 鑾峰彇鏈�鍚庝竴涓┖涓偣
+                const lastChild = device.children[device.children.length - 1];
+                // 娣辨嫹璐濇渶鍚庝竴涓厓绱狅紙鍖呮嫭宓屽鐨刢hildren锛�
+                const newChild = JSON.parse(JSON.stringify(lastChild));
+                if(newChild.label.includes('鍔犻珮')) {
+
+                }else {
+                  newChild.label = newChild.label + '-鍔犻珮'
+                  // 楂樺害澧炲姞20
+                  // newChild.height += 20;
+                  //濉旈珮 - 楂樺害  + 寰�涓婇澶氬皯绫�
+                  newChild.height += (device.ardTowerModel?.modelHeight  - newChild.height +  20) ;
+                  console.log('push11111111111111')
+                  // 娣诲姞鍒癱hildren鏁扮粍鏈熬
+                  device.children.push(newChild);
+                }
+            }
+          }
+          else if(index == currentLength -1) {
+            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
+                // 鑾峰彇鏈�鍚庝竴涓┖涓偣
+                const lastChild = device.children[0];
+                // 娣辨嫹璐濇渶涓�涓�涓厓绱狅紙鍖呮嫭宓屽鐨刢hildren锛�
+                const newChild = JSON.parse(JSON.stringify(lastChild));
+                if(newChild.label.includes('鍔犻珮')) {
+                }else {
+                  newChild.label = newChild.label + '-鍔犻珮绗竴涓偣'
+                  newChild.height += (device.ardTowerModel?.modelHeight  - newChild.height +  20) ;
+                  // 娣诲姞鍒癱hildren鏁扮粍鏈熬
+                  device.children.unshift(newChild);
+                }
+                
+            }
+          } else {
+            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
+                // 鑾峰彇鏈�鍚庝竴涓┖涓偣
+                const firstChild = device.children[0];
+                const lastChild = device.children[device.children.length - 1];
+                // 娣辨嫹璐濇渶涓�涓�涓厓绱狅紙鍖呮嫭宓屽鐨刢hildren锛�
+                const newFirstChild = JSON.parse(JSON.stringify(firstChild));
+                const newLastChildChild = JSON.parse(JSON.stringify(lastChild));
+                //楂樺害澧炲姞20
+                if(newFirstChild.label.includes('鍔犻珮')) {
+                }else {
+                    newFirstChild.label = newFirstChild.label + '-鍔犻珮'
+                    newFirstChild.height += (device.ardTowerModel?.modelHeight  - newFirstChild.height +  20) ;
+                    device.children.unshift(firstChild);
+                }
+                if(newLastChildChild.label.includes('鍔犻珮')) {
+                }else {
+                    newLastChildChild.label = newLastChildChild.label + '-鍔犻珮'
+                    newLastChildChild.height += (device.ardTowerModel?.modelHeight  - newLastChildChild.height +  20) ;
+                    device.children.push(newLastChildChild);
+                }
+            }
+          }
+      })
+    },
     //杩斿洖鏁版嵁杞崲鏍戠粨鏋�
     transformFlightData(data) {
+      console.log(data)
       const result = [];
 
       data.forEach(item => {
@@ -259,12 +381,29 @@
         }
       });
     },
+    generateId() {
+      return 'id_' + Math.random().toString(36).substring(2, 10);
+    },
     drawConnectionsWithLabels(devices) {
-      const airPoints = [];
+      if(lastConnectPolyline) {
+        viewer.entities.remove(lastConnectPolyline)
+        lastConnectPolyline = null
+      }
+        // 鐩存帴鎿嶄綔EntityCollection锛堟帹鑽愶級
+      const entitiesToRemove = [];
+      viewer.entities.values.forEach(entity => {
+        if (entity.id && entity.id.includes(this.deviceId)) {
+          entitiesToRemove.push(entity.id);
+        }
+      });
 
+      entitiesToRemove.forEach(id => {
+        viewer.entities.removeById(id);
+      });
+      const airPoints = [];
+      console.log(devices)
       devices.forEach(device => {
         if (!Array.isArray(device.children)) return;
-
         device.children.forEach(airPoint => {
           // 绌轰腑鐐逛綅缃�
           const airPos = Cesium.Cartesian3.fromDegrees(
@@ -276,6 +415,7 @@
           // 鉁� 娣诲姞绌轰腑鐐瑰疄浣撳拰 label
           viewer.entities.add({
             position: airPos,
+            id:device.id +'airpoint' + this.generateId(),
             point: {
               pixelSize: 6,
               color: Cesium.Color.YELLOW
@@ -305,6 +445,7 @@
 
               // 鉁� 娣诲姞鍦伴潰鐐瑰疄浣撳拰 label
               viewer.entities.add({
+                id:device.id +'groundpoint' + this.generateId(),
                 position: groundPos,
                 point: {
                   pixelSize: 6,
@@ -324,6 +465,7 @@
 
               // 鉁� 钃濊壊铏氱嚎杩炴帴锛氱┖涓偣 鉃� 鍦伴潰鐐�
               viewer.entities.add({
+                id:device.id +'polyline' + this.generateId(),
                 polyline: {
                   positions: [airPos, groundPos],
                   width: 2,
@@ -337,10 +479,10 @@
           }
         });
       });
-
+      console.log(airPoints)
       // 鉁� 榛勮壊瀹炵嚎杩炴帴鎵�鏈夌┖涓偣
       if (airPoints.length > 1) {
-        viewer.entities.add({
+        lastConnectPolyline = viewer.entities.add({
           polyline: {
             positions: airPoints,
             width: 3,
@@ -351,43 +493,44 @@
     },
     rotateAllPoints(dataList,towerLongitude,towerLatitude,towerhHight) {
       return dataList.map(item => {
-        console.log(item)
-        console.log(towerLongitude)
-        console.log(towerLatitude)
-        console.log(towerhHight)
-        const groundPoint = Cesium.Cartesian3.fromDegrees(item.longitude, item.latitude, item.height);
-        const towerPoint = Cesium.Cartesian3.fromDegrees(towerLongitude, towerLatitude, towerhHight);
-        let rotationAngle = Cesium.Math.toRadians(135)
-        // 鏃嬭浆鍦伴潰鐐规湰韬紙浼氬彉锛屼絾缁曡嚜韬棆杞笉浼氱Щ鍔級
-        const newGroundPoint = this.rotateAroundPoint( groundPoint,towerPoint, rotationAngle);
-        const newGroundCarto = Cesium.Cartographic.fromCartesian(newGroundPoint);
-        const newGround = {
-          ...item,
-          longitude: Cesium.Math.toDegrees(newGroundCarto.longitude),
-          latitude: Cesium.Math.toDegrees(newGroundCarto.latitude),
-          height: newGroundCarto.height
-        };
-        console.log(newGround)
-        // 澶勭悊瀛愮┖涓偣
-        newGround.children = item.children.map(child => {
-          const airPoint = Cesium.Cartesian3.fromDegrees(child.longitude, child.latitude, child.height);
-          const rotatedAirPoint = this.rotateAroundPoint( airPoint,towerPoint, rotationAngle);
-          const rotatedAirCarto = Cesium.Cartographic.fromCartesian(rotatedAirPoint);
-
-          return {
-            ...child,
-            longitude: Cesium.Math.toDegrees(rotatedAirCarto.longitude),
-            latitude: Cesium.Math.toDegrees(rotatedAirCarto.latitude),
-            height: rotatedAirCarto.height
+        if(!item.isDeal) {
+          const towerPoint = Cesium.Cartesian3.fromDegrees(towerLongitude, towerLatitude, towerhHight);
+          const newGround = {
+            ...item,
           };
-        });
-
-        return newGround;
+          if(item.id == this.deviceId ){
+            item.isDeal = true
+          } 
+          // 澶勭悊瀛愮┖涓偣
+          newGround.children = item.children?.map(child => {
+            const airPoint = Cesium.Cartesian3.fromDegrees(child.longitude, child.latitude, child.height);
+            const rotatedAirPoint = this.rotateAroundPoint( airPoint,towerPoint, rotationAngle);
+            const rotatedAirCarto = Cesium.Cartographic.fromCartesian(rotatedAirPoint);
+            child.longitude = Cesium.Math.toDegrees(rotatedAirCarto.longitude)
+            child.latitude = Cesium.Math.toDegrees(rotatedAirCarto.latitude)
+            child.height = rotatedAirCarto.height
+            child.children = child.children?.map(sonChild => {
+              const groundPoint = Cesium.Cartesian3.fromDegrees(sonChild.longitude, sonChild.latitude, sonChild.height);
+              const newGroundPoint = this.rotateAroundPoint( groundPoint,towerPoint, rotationAngle);
+              const newGroundCarto = Cesium.Cartographic.fromCartesian(newGroundPoint);
+              return {
+                ...sonChild,
+                longitude: Cesium.Math.toDegrees(newGroundCarto.longitude),
+                latitude: Cesium.Math.toDegrees(newGroundCarto.latitude),
+                height: newGroundCarto.height
+              };
+            });
+          });
+          console.log(newGround.children)
+          return newGround;
+        }
+         
       });
     },
     //聽璁$畻鐐笰缁曠偣B閫嗘椂閽堟棆杞寚瀹氳搴﹀悗鐨勬柊浣嶇疆
     //  绌轰腑鐐规垨鑰呭湴闈㈢偣绗涘崱灏斿潗鏍� 濉旂殑绗涘崱灏斿潗鏍�    濉旂殑鏈濆悜鍊�
     rotateAroundPoint(startPoint,pivotPoint,rotationAngle) {
+      console.log(rotationAngle)
       //聽鍒涘缓涓�涓粠B鐐瑰埌鏈湴鍧愭爣绯荤殑杞崲鐭╅樀锛堜笢鏂瑰悜涓篨杞达紝鍖楁柟鍚戜负Y杞达紝鍨傜洿鏂瑰悜涓篫杞达級
      const transformationMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(pivotPoint);
       //聽鑾峰彇涓栫晫鍧愭爣绯诲埌鏈湴鍧愭爣绯荤殑杞崲鐭╅樀
@@ -401,8 +544,51 @@
       //聽灏嗘棆杞悗鐨勫眬閮ㄥ潗鏍囪浆鎹㈠洖涓栫晫鍧愭爣绯�
      return Cesium.Matrix4.multiplyByPoint(transformationMatrix,聽new聽Cesium.Cartesian3(rotatedX,聽rotatedY,聽rotatedZ),聽new聽Cesium.Cartesian3());
     },
+    getRowKeys(row){
+      console.log(row)
+      return row.id +this.generateId()
+    },
     submit(){
+      console.log(this.treeData)
+
+      const routePointList = [];
+
+      this.treeData.forEach(device => {
+        device.children.forEach((airPoint, index) => {
+          routePointList.push({
+            routePointIndex: routePointList.length,
+            longitude: airPoint.longitude,
+            latitude: airPoint.latitude,
+            height: airPoint.height,
+            isStartAndEndPoint: false,
+            coordinatePointReq: {
+                height: airPoint.children[0].height,
+                latitude:airPoint.children[0].latitude,
+                longitude: airPoint.children[0].longitude
+              }
+          });
+        });
+      });
+
+      // 鏍囪棣栧熬涓� true
+      if (routePointList.length > 0) {
+        routePointList[0].isStartAndEndPoint = true;
+        routePointList[routePointList.length - 1].isStartAndEndPoint = true;
+      }
+
+      console.log(routePointList);
+      let params  = {
+        routePointList:routePointList
+      }
       console.log('鐢熸垚鑸嚎')
+      buildKmz(params).then(res=>{
+        if(res.code == 200) {
+           this.$message({
+              message: '鐢熸垚鑸嚎鎴愬姛',
+              type: 'success'
+            })
+        }
+      })
     }
   }
 }

--
Gitblit v1.9.3