From 0844efb61be18c6c3a6f04ff662ec42b4bce7c0c Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Mon, 13 Nov 2023 17:18:20 +0800
Subject: [PATCH] 解析json文件

---
 src/components/g-map/DroneControlPanel.vue |   51 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/src/components/g-map/DroneControlPanel.vue b/src/components/g-map/DroneControlPanel.vue
index 24731e6..549ed53 100644
--- a/src/components/g-map/DroneControlPanel.vue
+++ b/src/components/g-map/DroneControlPanel.vue
@@ -13,6 +13,10 @@
                         <Button :ghost="!flightController" size="small" @click="onClickFightControl">
                             {{ flightController ? '退出控制' : '进入控制' }}
                         </Button>
+
+                      <Button  size="small" @click="flyByPoints">
+                        图斑飞行
+                      </Button>
                     </div>
                 </div>
                 <div class="row">
@@ -313,6 +317,8 @@
 import DroneControlInfoPanel from './DroneControlInfoPanel.vue'
 import { noDebugCmdList as baseCmdList, DeviceCmdItem, DeviceCmd } from '/@/types/device-cmd'
 import { useDockControl } from './use-dock-control'
+import { flyByArea, Point } from '/@/api/wayline'
+import { parseJsonFile } from '/@/utils/geo-utils'
 
 const props = defineProps<{
     sn: string,
@@ -340,11 +346,19 @@
     cmd: cmdItem.cmdKey,
     action: cmdItem.action
   }, false)
-  if (result && flightController.value) {
+  // if (result && flightController.value) {
+  //   message.success('返航成功')
+  //   exitFlightCOntrol()
+  // } else {
+  //   message.warn('请先进入控制!')
+  // }
+  // cmdItem.loading = false
+  if (result) {
     message.success('返航成功')
+  }
+  // 退出飞行控制
+  if (result && flightController.value) {
     exitFlightCOntrol()
-  } else {
-    message.warn('请先进入控制!')
   }
   cmdItem.loading = false
 }
@@ -474,6 +488,37 @@
   enterFlightControl()
 }
 
+// 根据图斑飞行
+async function flyByPoints () {
+  // 半径m
+  const radius = 7000
+  const dockPoint:Point = reactive({
+    lon: props.deviceInfo.dock.basic_osd.longitude,
+    lat: props.deviceInfo.dock.basic_osd.latitude
+  })
+  const jsonData = await parseJsonFile('../src/assets/jsonData/图斑_FeaturesToJSON(1).json')
+  const sn = props.sn
+  const features = jsonData.features
+  const list = []
+
+  features.forEach(feature => {
+    const areaList = []
+    feature.geometry.coordinates[0].forEach(areaPoint => {
+      console.log('areaPoint:', areaPoint)
+      const point = {
+        lon: areaPoint[0],
+        lat: areaPoint[1]
+      }
+      areaList.push(point)
+    })
+    list.push(areaList)
+  })
+
+  flyByArea(sn, dockPoint, list, radius).then(res => {
+    console.log(res, '----------------')
+  })
+}
+
 // 进入飞行控制
 async function enterFlightControl () {
   if (!clientId.value) {

--
Gitblit v1.9.3