forked from drone/command-center-dashboard

罗广辉
2025-04-21 9631f218829b4ce3951099837a676916f40d5038
fix: 单个机巢详情里面的飞行建议100%
8 files modified
128 ■■■■■ changed files
src/api/home/index.js 6 ●●●● patch | view | raw | blame | history
src/components/CommonWeather.vue 22 ●●●● patch | view | raw | blame | history
src/const/drc.js 7 ●●●●● patch | view | raw | blame | history
src/hooks/useMapAggregation/useMapAggregation.js 21 ●●●● patch | view | raw | blame | history
src/store/modules/home.js 4 ●●●● patch | view | raw | blame | history
src/utils/cesium/mapUtil.js 14 ●●●●● patch | view | raw | blame | history
src/views/Home/Home.vue 33 ●●●●● patch | view | raw | blame | history
src/views/SignMachineNest/SignMachineNest.vue 21 ●●●●● patch | view | raw | blame | history
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
    })
}
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(() => {
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},
]
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()
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;
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 };
}
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>
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 = () => {