From 55fcb97a3d487f54353564f1e402e4d4b61feee9 Mon Sep 17 00:00:00 2001
From: GuLiMmo <2820890765@qq.com>
Date: Tue, 12 Mar 2024 17:54:05 +0800
Subject: [PATCH] update:kmz/json转换、kmz打包后无法解析等

---
 src/utils/cesium/use-kmz-tsa.ts |  150 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 131 insertions(+), 19 deletions(-)

diff --git a/src/utils/cesium/use-kmz-tsa.ts b/src/utils/cesium/use-kmz-tsa.ts
index 3017b97..665aa36 100644
--- a/src/utils/cesium/use-kmz-tsa.ts
+++ b/src/utils/cesium/use-kmz-tsa.ts
@@ -1,8 +1,13 @@
 import { ref, getCurrentInstance } from 'vue'
-import { analyzeKmzFile, getKmlParams, generateKmlFormat } from '/@/utils/cesium/kmz'
+import {
+  analyzeKmzFile,
+  getKmlParams,
+  generateKmlFormat,
+  XMLToJSON,
+  JSONToXML
+} from '/@/utils/cesium/kmz'
 import JSZIP from 'jszip'
 import { saveAs } from 'file-saver'
-import { point } from '@turf/turf'
 
 const JsZip = new JSZIP()
 
@@ -12,6 +17,126 @@
 })
 const kmlStr = ref('')
 const kmzFile = ref<any>(null)
+
+const template = ref({
+  author: '',
+  createTime: '',
+  updateTime: '',
+  missionConfig: {
+    flyToWaylineMode: 'safely',
+    finishAction: 'goHome',
+    exitOnRCLost: 'goContinue',
+    executeRCLostAction: 'goBack',
+    takeOffSecurityHeight: 20,
+    takeOffRefPoint: '0.000000,0.000000,0.000000',
+    takeOffRefPointAGLHeight: 0,
+    globalTransitionalSpeed: 15,
+    globalRTHHeight: 80,
+    droneInfo: {
+      droneEnumValue: 0,
+      droneSubEnumValue: 0,
+    },
+    payloadInfo: {
+      payloadEnumValue: 0,
+      payloadSubEnumValue: 0,
+      payloadPositionIndex: 0,
+    },
+  },
+  Folder: {
+    templateType: 'waypoint',
+    useGlobalTransitionalSpeed: 0,
+    templateId: 0,
+    waylineCoordinateSysParam: {
+      coordinateMode: 'WGS84',
+      heightMode: 'EGM96',
+      globalShootHeight: 50,
+      positioningType: 'GPS',
+      surfaceFollowModeEnable: 1,
+      surfaceRelativeHeight: 100,
+    },
+    autoFlightSpeed: 7,
+    gimbalPitchMode: 'usePointSetting',
+    globalWaypointHeadingParam: {
+      waypointHeadingMode: 'followWayline',
+      waypointHeadingAngle: 0,
+      waypointPoiPoint: '0.000000,0.000000,0.000000',
+      waypointHeadingPathMode: 'followBadArc',
+    },
+    globalWaypointTurnMode: 'toPointAndStopWithDiscontinuityCurvature',
+    globalUseStraightLine: 0,
+    Placemark: [
+      {
+        Point: {
+          coordinates: '',
+        },
+        index: 0,
+        ellipsoidHeight: 0,
+        height: 0,
+        useGlobalHeight: 0,
+        useGlobalSpeed: 0,
+        useGlobalHeadingParam: 1,
+        useGlobalTurnParam: 0,
+        gimbalPitchAngle: 0,
+        actionGroup: {
+          actionGroupId: 0,
+          actionGroupStartIndex: 1,
+          actionGroupEndIndex: 1,
+          actionGroupMode: 'sequence',
+          actionTrigger: {
+            actionTriggerType: 'reachPoint',
+          },
+          action: [],
+        },
+      },
+    ],
+  },
+})
+const waylines = ref({
+  missionConfig: {
+    flyToWaylineMode: 'safely',
+    finishAction: 'goHome',
+    exitOnRCLost: 'goContinue',
+    executeRCLostAction: 'hover',
+    takeOffSecurityHeight: 20,
+    globalTransitionalSpeed: 10,
+    distance: 0,
+    duration: 0,
+    droneInfo: {
+      droneEnumValue: 67,
+      droneSubEnumValue: 0,
+    },
+    payloadInfo: {
+      payloadEnumValue: 52,
+      payloadSubEnumValue: 0,
+      payloadPositionIndex: 0,
+    },
+  },
+  Folder: {
+    templateId: 0,
+    executeHeightMode: 'WGS84',
+    waylineId: 0,
+    autoFlightSpeed: 10,
+    Placemark: [
+      {
+        Point: {
+          coordinates: '0.000000, 0.000000',
+        },
+        index: 0,
+        executeHeight: 116.57,
+        waypointSpeed: 10,
+        waypointHeadingParam: {
+          waypointHeadingMode: 'followWayline',
+        },
+        waypointTurnParam: {
+          waypointTurnMode: 'toPointAndStopWithDiscontinuityCurvature',
+          waypointTurnDampingDist: 0,
+        },
+        useStraightLine: 1,
+        actionGroup: [],
+      },
+    ],
+  },
+})
 
 // 点位参数
 const placemark: any = {
@@ -44,8 +169,8 @@
 const useKmzTsa = () => {
   const init = async (fileUrl: string, fileContent?: string) => {
     const fileRes = await analyzeKmzFile(fileUrl)
-    kmzFile.value = fileRes.file
-    const kmzRes = await fileRes.content
+    kmzFile.value = fileRes.zip
+    const kmzRes = await fileRes.fileInfoObj['wpmz/template.kml']
     if (fileContent) {
       kmlStr.value = fileContent
       return false
@@ -53,7 +178,6 @@
     kmlStr.value = kmzRes
     return kmzRes
   }
-
   const create = () => {
     const nowTime = new Date().getTime()
     const str = `
@@ -72,9 +196,6 @@
     `
     kmlStr.value = str
   }
-
-  // const write = (settingParmas: any = {}, name: string) => {
-  // }
   const writePoint = (settingParmas: any = {}, place: string, pointNumber: number = 0) => {
     Object.keys(settingParmas).forEach((key: string) => {
       placemark[key] = settingParmas[key]
@@ -126,9 +247,6 @@
       })
     }
   }
-
-  const del = () => {}
-
   const edit = (settingParmas: any = {}, keyName?: string, isKeyWpml: boolean = false) => {
     Object.keys(settingParmas).forEach((key: string) => {
       const regxVal: any = getKmlParams(kmlStr.value, true, {
@@ -151,7 +269,7 @@
           // 文件中的海拔高度
           const takeOffRefPointAGLHeightRegxStr = getKmlParams(kmlStr.value, true, {
             name: 'takeOffRefPointAGLHeight',
-            findRegx: '([\\s\\S]*?)'
+            findRegx: '([\\s\\S]*?)',
           }) || ['', '0']
           const posterHeight = Number(takeOffRefPointAGLHeightRegxStr[1])
           // 获取每个点是否使用全局高度
@@ -179,7 +297,6 @@
                 name: 'height',
                 findRegx: '([\\s\\S]*?)',
               })
-              console.log(heightRegxVal)
             }
           })
         }
@@ -192,11 +309,7 @@
   }
 
   const save = () => {
-    JsZip.file('wpmz/template.kml', kmlStr.value)
-    kmzFile.value.file('wpmz/template.kml', kmlStr.value)
-    JsZip.generateAsync({ type: 'blob' }).then((content) => {
-      saveAs(content, '新建航线-' + new Date().toLocaleString() + '.kmz')
-    })
+    console.log('存在问题')
   }
 
   return {
@@ -204,7 +317,6 @@
     create,
     // write,
     writePoint,
-    del,
     edit,
     save,
   }

--
Gitblit v1.9.3