From c1b252b4890ae7df1720955cb7caba184d78798f Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Tue, 27 Jan 2026 11:32:32 +0800
Subject: [PATCH] feat:数据驾驶舱部分调整
---
applications/drone-command/src/components/map-container/common-cesium-map.vue | 84 ++++++++++++++++++++++++++++++++++--------
1 files changed, 68 insertions(+), 16 deletions(-)
diff --git a/applications/drone-command/src/components/map-container/common-cesium-map.vue b/applications/drone-command/src/components/map-container/common-cesium-map.vue
index 3345c78..e728ff2 100644
--- a/applications/drone-command/src/components/map-container/common-cesium-map.vue
+++ b/applications/drone-command/src/components/map-container/common-cesium-map.vue
@@ -3,7 +3,7 @@
</template>
<script setup>
-import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
+import { onBeforeUnmount, onMounted, watch } from 'vue'
import { PublicCesium } from '@/utils/cesium/publicCesium'
import { loadJaAdminBoundary, removeJaAdminBoundary } from '@/utils/cesium/adminBoundary'
@@ -60,8 +60,13 @@
const emit = defineEmits(['ready', 'height-change', 'stage-change'])
const mapId = props.domId || `common-cesium-map-${Math.random().toString(36).slice(2, 10)}`
-const viewInstance = ref(null)
-const viewer = ref(null)
+let viewInstance = null
+let viewer = null
+const ADMIN_BOUNDARY_NAMES = {
+ boundary: 'jaBoundarySource',
+ line: 'jaBoundaryLineSource',
+ label: 'jaBoundaryLabelSource',
+}
let adminBoundarySources = null
let initialized = false
let removeCameraListener = null
@@ -69,7 +74,7 @@
const initMap = async () => {
if (initialized) return
initialized = true
- viewInstance.value = new PublicCesium({
+ viewInstance = new PublicCesium({
dom: mapId,
flatMode: props.flatMode,
terrain: props.terrain,
@@ -77,16 +82,16 @@
boundary: props.boundary,
contour: props.contour,
})
- viewer.value = viewInstance.value.getViewer()
+ viewer = viewInstance.getViewer()
if (props.showAdminBoundary) {
- adminBoundarySources = await loadJaAdminBoundary(viewer.value, {
+ adminBoundarySources = await loadJaAdminBoundary(viewer, {
zoomTo: props.zoomToBoundary,
})
}
if (props.enableStageEmit) {
let lastStage = ''
const onCameraChanged = () => {
- const height = viewer.value?.camera?.positionCartographic?.height
+ const height = viewer?.camera?.positionCartographic?.height
if (height == null) return
emit('height-change', height)
let stage = 'mid'
@@ -97,10 +102,10 @@
emit('stage-change', stage)
}
}
- viewer.value?.camera?.changed?.addEventListener(onCameraChanged)
- removeCameraListener = () => viewer.value?.camera?.changed?.removeEventListener(onCameraChanged)
+ viewer?.camera?.changed?.addEventListener(onCameraChanged)
+ removeCameraListener = () => viewer?.camera?.changed?.removeEventListener(onCameraChanged)
}
- emit('ready', { viewer: viewer.value, publicCesium: viewInstance.value })
+ emit('ready', { viewer, publicCesium: viewInstance })
}
watch(
@@ -116,15 +121,62 @@
onBeforeUnmount(() => {
if (removeCameraListener) removeCameraListener()
- removeJaAdminBoundary(viewer.value, adminBoundarySources)
- viewInstance.value?.viewerDestroy?.()
+ removeJaAdminBoundary(viewer, adminBoundarySources)
+ adminBoundarySources = null
+ viewInstance?.viewerDestroy?.()
})
-const getMap = () => ({ viewer: viewer.value, publicCesium: viewInstance.value })
-const getViewer = () => viewer.value
-const getPublicCesium = () => viewInstance.value
+const setAdminBoundaryVisible = async visible => {
+ if (!viewer) return
+ const removeByNames = () => {
+ Object.values(ADMIN_BOUNDARY_NAMES).forEach(name => {
+ const sources = viewer.dataSources.getByName(name) || []
+ sources.forEach(source => viewer.dataSources.remove(source))
+ })
+ }
+ const resolveSources = () => {
+ if (adminBoundarySources) return adminBoundarySources
+ const boundarySource = viewer.dataSources.getByName(ADMIN_BOUNDARY_NAMES.boundary)?.[0] ?? null
+ const lineSource = viewer.dataSources.getByName(ADMIN_BOUNDARY_NAMES.line)?.[0] ?? null
+ const labelSource = viewer.dataSources.getByName(ADMIN_BOUNDARY_NAMES.label)?.[0] ?? null
+ if (boundarySource || lineSource || labelSource) {
+ adminBoundarySources = { boundarySource, lineSource, labelSource }
+ }
+ return adminBoundarySources
+ }
+ const setVisible = (source, next) => {
+ if (!source) return
+ source.show = next
+ source.entities?.values?.forEach(entity => {
+ entity.show = next
+ })
+ }
+ const sources = resolveSources()
+ if (!visible) {
+ if (sources) {
+ removeJaAdminBoundary(viewer, sources)
+ adminBoundarySources = null
+ }
+ removeByNames()
+ return
+ }
+ if (sources) {
+ const { boundarySource, lineSource, labelSource } = sources
+ setVisible(boundarySource, true)
+ setVisible(lineSource, true)
+ setVisible(labelSource, true)
+ return
+ }
+ adminBoundarySources = await loadJaAdminBoundary(viewer, {
+ zoomTo: false,
+ })
+}
-defineExpose({ getMap, getViewer, getPublicCesium })
+const getMap = () => ({ viewer, publicCesium: viewInstance })
+const getViewer = () => viewer
+const getPublicCesium = () => viewInstance
+
+defineExpose({ getMap, getViewer, getPublicCesium, setAdminBoundaryVisible })
</script>
<style scoped lang="scss">
--
Gitblit v1.9.3