From 9631f218829b4ce3951099837a676916f40d5038 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Mon, 21 Apr 2025 18:22:35 +0800
Subject: [PATCH] fix: 单个机巢详情里面的飞行建议100%

---
 src/utils/cesium/mapUtil.js                      |   14 ++++
 src/const/drc.js                                 |    7 ++
 src/store/modules/home.js                        |    4 +
 src/components/CommonWeather.vue                 |   22 +++---
 src/views/SignMachineNest/SignMachineNest.vue    |   21 ------
 src/hooks/useMapAggregation/useMapAggregation.js |   21 +-----
 src/api/home/index.js                            |    6 +-
 src/views/Home/Home.vue                          |   33 +++++++++++
 8 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/src/api/home/index.js b/src/api/home/index.js
index e5c8ed3..cd3b5d6 100644
--- a/src/api/home/index.js
+++ b/src/api/home/index.js
@@ -124,9 +124,9 @@
 
 // 根据经纬度获取区域code
 export const getAreaCodeApi = (params) => {
-	return axios({
-		url: `https://restapi.amap.com/v3/geocode/regeo`,
-		method: 'post',
+	return request({
+		url: `/drone-device-core/map/amap/searchByLatLng?`,
+		method: 'get',
 		params
 	})
 }
diff --git a/src/components/CommonWeather.vue b/src/components/CommonWeather.vue
index abec0ec..9e260c7 100644
--- a/src/components/CommonWeather.vue
+++ b/src/components/CommonWeather.vue
@@ -6,8 +6,8 @@
 			<img src="@/assets/images/home/homeLeft/tq.png" alt="" />
 			<span class="tq">{{ weather }}</span>
 			<span class="tq">风速:{{ windVelocity }} </span>
-			<span v-if="flylevel >= 5" :class="[isFly === '适合飞行' ? 'qk' : isFly === '禁止飞行' ? 'redqk' : 'yellowqk']">{{
-				isFly
+			<span v-if="flightAdvice" :class="[flightAdvice === '适合飞行' ? 'qk' : flightAdvice === '禁止飞行' ? 'redqk' : 'yellowqk']">{{
+					flightAdvice
 			}}</span>
 		</div>
 	</div>
@@ -16,6 +16,11 @@
 <script setup>
 import dayjs from 'dayjs'
 import { getDroneSuggest } from '@/api/home/common'
+import { useStore } from 'vuex'
+import { ElMessage } from 'element-plus'
+
+const store = useStore()
+const flySuggest = computed(() => store.state.home.flySuggest)
 
 const time = ref('')
 const updateTime = () => {
@@ -24,26 +29,21 @@
 
 // 天气
 const weather = ref('')
-// 是否适合飞行
-const isFly = ref('')
+
 // 风速
 const windVelocity = ref('')
 // 区县级
-const flylevel = ref('')
+const flightAdvice = computed(() => flySuggest.value?.flightAdvice)
+
 // 获取天气建议
 const getWeatherSuggest = () => {
+	// ElMessage.success('wobeichonghzil')
 	getDroneSuggest().then(res => {
 		if (res.data.code !== 0) return
 		weather.value = res.data.data.weather
-		isFly.value = res.data.data.flightAdvice
 		windVelocity.value = res.data.data.windPower
-		flylevel.value = res.data.data.adcode.replace(/0+$/, "").length
 	})
 }
-
-
-
-
 
 let intervalTime
 onMounted(() => {
diff --git a/src/const/drc.js b/src/const/drc.js
index 29c7a56..e264b8c 100644
--- a/src/const/drc.js
+++ b/src/const/drc.js
@@ -38,3 +38,10 @@
 	{name:'悬停',value:'hover',img:hoverImg},
 	{name:'拍照',value:'takePhoto',img:takePhotoImg},
 ]
+
+// 地图层级
+export const MAP_LEVEL = [
+	{ name: '县',heightRange: [0, 48651], height: 31753},
+	{ name: '市',heightRange: [48651, 314863], height: 257731},
+	{ name: '省',heightRange: [314863, 3796280000], height: 1987280},
+]
diff --git a/src/hooks/useMapAggregation/useMapAggregation.js b/src/hooks/useMapAggregation/useMapAggregation.js
index d46d74a..739da34 100644
--- a/src/hooks/useMapAggregation/useMapAggregation.js
+++ b/src/hooks/useMapAggregation/useMapAggregation.js
@@ -1,8 +1,7 @@
 import * as Cesium from 'cesium'
 import aggregationImg from '@/assets/images/home/useUavHome/aggregation.png'
 import eventAggregationImg from '@/assets/images/home/useUavHome/eventAggregationImg.png'
-import uavImg from '@/assets/images/home/useUavHome/uavImg.png'
-
+import _ from 'lodash'
 import { getEventImage } from '@/utils/stateToImageMap/event'
 import { getDroneStatusImage } from '@/utils/stateToImageMap/drone'
 
@@ -15,6 +14,7 @@
 
 // hook
 import { useMapHandlerClick } from '@/hooks/components/useMapHandlerClick'
+import { MAP_LEVEL } from '@/const/drc'
 
 /**
  * 机巢聚合功能
@@ -56,19 +56,8 @@
     }
   })
 
-  let scalingJudgment = [
-    { name: '县', splashedList: [], gJson: null, show: false, outline: {}, value: [0, 48651], height: 31753 },
-    { name: '市', splashedList: [], gJson: null, show: false, outline: {}, value: [48651, 314863], height: 257731 },
-    {
-      name: '省',
-      splashedList: [],
-      gJson: null,
-      show: false,
-      outline: {},
-      value: [314863, 3796280000],
-      height: 1987280,
-    },
-  ]
+  let scalingJudgment = _.cloneDeep(MAP_LEVEL).map(i => ({...i,gJson: null,splashedList:[], show: false, outline: {}}))
+
   let viewer = null
   let active = null
 
@@ -100,7 +89,7 @@
     // 根据高度展示对应的 gJson
     for (let [index, item] of scalingJudgment.entries()) {
       if (!item.show) return
-      if (height > item.value[0] && height <= item.value[1]) {
+      if (height > item.heightRange[0] && height <= item.heightRange[1]) {
         if (active === item.name) return
         active = item.name
         removeEntities()
diff --git a/src/store/modules/home.js b/src/store/modules/home.js
index 73aa14f..a19f23c 100644
--- a/src/store/modules/home.js
+++ b/src/store/modules/home.js
@@ -15,9 +15,13 @@
     eventTimeType: 'day',
     eventTimeParams: 'CURRENT_WEEK',
     eventTimeRang: '',
+		flySuggest:{},//飞行建议
   },
   actions: {},
   mutations: {
+		setFlySuggest: (state, data) => {
+			state.flySuggest = data;
+		},
 		setUserAreaPosition: (state, data) => {
 			setStore({ name: 'userAreaPosition', content: data })
 			state.userAreaPosition = data;
diff --git a/src/utils/cesium/mapUtil.js b/src/utils/cesium/mapUtil.js
index 73b9fbf..e0230e2 100644
--- a/src/utils/cesium/mapUtil.js
+++ b/src/utils/cesium/mapUtil.js
@@ -366,3 +366,17 @@
 		offset: new Cesium.HeadingPitchRange(0, 0, boundingSphere.radius * rangeMultiple),
 	})
 }
+
+// 获取视口地图中心点
+export function getMapCenterPoint(viewer) {
+	const centerResult = viewer.camera.pickEllipsoid(
+		new Cesium.Cartesian2(
+			viewer.canvas.clientWidth / 2,
+			viewer.canvas.clientHeight / 2
+		)
+	);
+	const curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(centerResult);
+	const longitude = (curPosition.longitude * 180) / Math.PI;
+	const latitude = (curPosition.latitude * 180) / Math.PI;
+	return { longitude, latitude };
+}
diff --git a/src/views/Home/Home.vue b/src/views/Home/Home.vue
index 0c697e8..e050f03 100644
--- a/src/views/Home/Home.vue
+++ b/src/views/Home/Home.vue
@@ -32,6 +32,11 @@
 import cesiumOperation from '@/utils/cesium-tsa'
 import EventOverviewDetail from '@/views/Home/EventOverviewDetail/EventOverviewDetail.vue'
 import AINowFly from '@/views/Home/AINowFly.vue'
+import { getMapCenterPoint } from '@/utils/cesium/mapUtil'
+import { getAreaCodeApi } from '@/api/home'
+import { getDroneSuggest } from '@/api/home/common'
+import { MAP_LEVEL } from '@/const/drc'
+import _ from 'lodash'
 
 const store = useStore()
 const { _init, viewerDestory } = cesiumOperation()
@@ -52,7 +57,35 @@
 	viewerDestory()
 })
 
+// 获取飞行建议
+function getFlySuggestion(){
+	const viewer = window.$viewer
+	const {longitude,latitude} = getMapCenterPoint(viewer)
+	let height = viewer.camera.positionCartographic.height;
+	if (height > MAP_LEVEL[0].heightRange[1]) {
+		store.commit('setFlySuggest', {})
+		return
+	}
+	const params = { location: longitude + ',' + latitude}
+	getAreaCodeApi(params).then(res => {
+		const { adcode:areaCode } = res.data.data.regeocode.addressComponent
+		if (!areaCode) return
+		return getDroneSuggest({areaCode})
+	}).then(res => {
+		const setFlySuggest = _.pick(res.data.data,['windPower','flightAdvice']) || {}
+		store.commit('setFlySuggest', setFlySuggest)
+	})
+}
+
+onBeforeUnmount(() =>{
+	window.$viewer.camera.moveEnd.removeEventListener(getFlySuggestion);
+})
+
 onMounted(() => {
 	_init('cesium')
+	nextTick(() => {
+		getFlySuggestion()
+		window.$viewer.camera.moveEnd.addEventListener(getFlySuggestion);
+	})
 })
 </script>
diff --git a/src/views/SignMachineNest/SignMachineNest.vue b/src/views/SignMachineNest/SignMachineNest.vue
index 48913f7..2bcff88 100644
--- a/src/views/SignMachineNest/SignMachineNest.vue
+++ b/src/views/SignMachineNest/SignMachineNest.vue
@@ -40,8 +40,8 @@
 	getDeviceDetail(singleUavHome.value.device_sn).then(res => {
 		const result = res.data.data
 		dockDetails.value = result
-    const storageObj  = _.pick(result, ['latitude', 'longitude'])
-		setSingleUavAreaCode(storageObj)
+    const storageObj  = _.pick(result, ['latitude', 'longitude']) || {}
+		store.commit('setSingleUavHome',{...singleUavHome.value, ...storageObj})
 		initDroneEntity({
 			lng: result.longitude,
 			lat: result.latitude,
@@ -50,23 +50,6 @@
 		workspaceId.value = result.workspace_id
 	})
 }
-
-// 设置单机巢得位置信息
-const setSingleUavAreaCode = (position) =>{
-	store.commit('setSingleUavHome',{...singleUavHome.value, ...position})
-	const params = {
-		output:'json',
-		location: position.longitude+','+position.latitude,
-		key:'6c3ea75b215f0c0efcbcfdf13273991b',
-		radius:'0',
-		extensions:'base',
-	}
-	// todo 2025年4月23号 后端提供接口然后对接
-	// getAreaCodeApi(params).then(res => {
-	// 	console.log(res,66666666)
-	// })
-}
-
 
 // 获取机巢统计数据 提供给左右侧组件使用
 const getMachineData = () => {

--
Gitblit v1.9.3