| | |
| | | <template> |
| | | <HomeLeft></HomeLeft> |
| | | <!-- <div>中间搜索</div> --> |
| | | <HomeRight></HomeRight> |
| | | <SearchBox /> |
| | | <div :key="selectedAreaCode"> |
| | | <!-- 单个机巢页面--> |
| | | <SignMachineNest v-if="singleUavHome?.device_sn" :key="singleUavHome?.device_sn"/> |
| | | <!-- 事件概述详细信息页面--> |
| | | <EventOverviewDetail v-else-if="isEventOverviewDetail" /> |
| | | |
| | | <!-- 智引即飞 --> |
| | | <AINowFly v-else-if="isAINowFly" /> |
| | | <!-- 首页默认的页面--> |
| | | <template v-else> |
| | | <HomeLeft /> |
| | | <HomeRight /> |
| | | </template> |
| | | </div> |
| | | |
| | | |
| | | <SearchBox /> |
| | | <RSide /> |
| | | <Footer /> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import HomeRight from './components/HomeRight/HomeRight.vue'; |
| | | import HomeLeft from '@/views/Home/components/HomeLeft/HomeLeft.vue'; |
| | | import { getAggregation } from '@/views/Home/aggregation'; |
| | | import SearchBox from '@/views/Home/SearchBox.vue'; |
| | | import jiangxi from '@/assets/geojson/jiangxi.json'; |
| | | import nanchang from '@/assets/geojson/nanchang.json'; |
| | | import jiangxishi from '@/assets/geojson/jiangxishi.json'; |
| | | import zg from '@/assets/geojson/zg.json'; |
| | | import * as Cesium from 'cesium'; |
| | | import HomeRight from '@/views/Home/HomeRight/HomeRight.vue' |
| | | import HomeLeft from '@/views/Home/HomeLeft/HomeLeft.vue' |
| | | import SearchBox from '@/views/Home/SearchBox.vue' |
| | | import SignMachineNest from '@/views/SignMachineNest/SignMachineNest.vue' |
| | | import { useStore } from 'vuex' |
| | | import Footer from '@/views/Home/Footer.vue' |
| | | import RSide from '@/views/Home/RSide.vue' |
| | | import { onMounted } from 'vue' |
| | | 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 list = [ |
| | | { name: '县', value: [0,48651], gJson: null }, |
| | | { name: '市', value: [48651,314863], gJson: jiangxishi }, |
| | | { name: '省', value: [314863,1169651], gJson: jiangxi }, |
| | | { name: '国', value: [1169651,37962800], gJson: zg }, |
| | | ]; |
| | | let viewer = null; |
| | | const active = ref(''); |
| | | const init = () => { |
| | | determineScaling(); |
| | | viewer.camera.moveEnd.addEventListener(() => { |
| | | determineScaling(); |
| | | }); |
| | | }; |
| | | const store = useStore() |
| | | const { _init, viewerDestory } = cesiumOperation() |
| | | |
| | | const determineScaling = () => { |
| | | let height = viewer.camera.positionCartographic.height; |
| | | console.log('缩放结束,高度为:', height); |
| | | // 根据高度展示对应的 gJson |
| | | for (let item of list) { |
| | | // if (height < item.value) { |
| | | if (height > item.value[0] && height <= item.value[1]) { |
| | | if (active.value !== item.name) { |
| | | viewer.dataSources.removeAll(true); |
| | | viewer.entities.removeAll(); |
| | | active.value = item.name; |
| | | if (item.gJson) { |
| | | aggregation(item); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | }; |
| | | const singleUavHome = computed(() => store.state.home.singleUavHome) |
| | | const isEventOverviewDetail = computed(() => store.state.home.isEventOverviewDetail) |
| | | const isAINowFly = computed(() => store.state.home.footActiveIndex === 5) |
| | | const userAreaCode = computed(() => store.state.user.userInfo.detail.areaCode) |
| | | const selectedAreaCode = computed(() => store.state.user.selectedAreaCode) |
| | | |
| | | const aggregation = item => { |
| | | const featuresList = item.gJson.features.map(item => ({ |
| | | name: item.properties.name, |
| | | position: item.properties.center, |
| | | })); |
| | | // 遍历特征并添加实体 |
| | | featuresList.forEach(feature => { |
| | | if (!feature.position) return; |
| | | const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1]); |
| | | viewer.entities.add({ |
| | | position: position, |
| | | label: { |
| | | // 随机整数 |
| | | text: feature.name + Math.floor(Math.random() * 100), |
| | | font: '14pt monospace', |
| | | fillColor: Cesium.Color.WHITE, |
| | | outlineColor: Cesium.Color.BLACK, |
| | | outlineWidth: 2, |
| | | style: Cesium.LabelStyle.FILL_AND_OUTLINE, |
| | | verticalOrigin: Cesium.VerticalOrigin.BOTTOM, |
| | | pixelOffset: new Cesium.Cartesian2(0, -9), |
| | | }, |
| | | }); |
| | | }); |
| | | // 加载新的 GeoJSON 数据 |
| | | Cesium.GeoJsonDataSource.load(item.gJson).then(dataSource => { |
| | | viewer.dataSources.add(dataSource); |
| | | item.dataSource = dataSource; // 保存数据源以便后续删除 |
| | | // 获取数据源中的实体 |
| | | const entities = dataSource.entities.values; |
| | | entities.forEach(entity => { |
| | | entity.polygon.material = new Cesium.ColorMaterialProperty( |
| | | Cesium.Color.YELLOW.withAlpha(0) // 透明填充 |
| | | ); |
| | | entity.polygon.outline = true; // 显示边框 |
| | | entity.polygon.outlineColor = Cesium.Color.YELLOW; // 黑色边框 |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | |
| | | onUnmounted(() => { |
| | | store.commit('setSingleUavHome', null) |
| | | store.commit('setIsEventOverviewDetail', false) |
| | | store.commit('setFootActiveIndex', 0) |
| | | store.commit('setSelectedAreaCode', null) |
| | | 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(() => { |
| | | nextTick(() => { |
| | | viewer = window.$viewer; |
| | | init(); |
| | | }); |
| | | }); |
| | | _init('cesium') |
| | | nextTick(() => { |
| | | getFlySuggestion() |
| | | window.$viewer.camera.moveEnd.addEventListener(getFlySuggestion); |
| | | }) |
| | | }) |
| | | </script> |