From afbb44a7f2fe594d37cba5ee83cd0c49963e85a9 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Fri, 30 Jan 2026 13:50:03 +0800
Subject: [PATCH] feat:首页数据驾驶舱加载调整处理

---
 applications/drone-command/src/components/map-container/device-map-container.vue |  328 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 275 insertions(+), 53 deletions(-)

diff --git a/applications/drone-command/src/components/map-container/device-map-container.vue b/applications/drone-command/src/components/map-container/device-map-container.vue
index f7fb7e9..82c1f57 100644
--- a/applications/drone-command/src/components/map-container/device-map-container.vue
+++ b/applications/drone-command/src/components/map-container/device-map-container.vue
@@ -48,8 +48,10 @@
 import * as Cesium from 'cesium'
 import CommonCesiumMap from '@/components/map-container/common-cesium-map.vue'
 import { geomAnalysis } from '@ztzf/utils'
+import { buildEllipsePositions } from '@/utils/cesium/shapeTools'
+import { AREA_TYPE_STYLE_MAP, BUFFER_LEVEL_STYLES, DEFAULT_AREA_STYLE } from '@ztzf/constants'
 import { fwDefenseZonePageApi } from '@/views/areaManage/defenseZone/defenseZoneApi'
-import { fwAreaDividePageApi } from '@/views/areaManage/partition/partitionApi'
+import { fwAreaDivideListApi } from '@/views/areaManage/partition/partitionApi'
 import { fwDefenseSceneListApi } from '@/views/areaManage/sceneConfig/sceneConfigApi'
 import { cockpitAggregationApi } from '@/api/dataCockpit'
 import layerControlIcon from '@/assets/images/dataCockpit/layerControl.png'
@@ -67,11 +69,13 @@
 	createRadialGradientMaterial,
 	getTexturedVertexFormat,
 } from './device-map-materials'
+import { getPointPositionsHeight } from '@/utils/cesium/mapUtil'
 import dzIcon from '@/assets/images/dataCockpit/map/dz-map-layer.png'
 import yxIcon from '@/assets/images/dataCockpit/map/yx-map-layer.png'
 
 const CLUSTER_HEIGHT = 100000
 const DETAIL_HEIGHT = 10000
+const POLYGON_HEIGHT_M = 0.2
 
 const props = defineProps({
 	onlineDevices: {
@@ -110,8 +114,8 @@
 let deviceRingFillPrimitives = []
 let defenseZonePrimitive = null
 let defenseZoneOutlinePrimitive = null
-let partitionPrimitive = null
-let partitionOutlinePrimitive = null
+let partitionFillPrimitives = []
+let partitionOutlinePrimitives = []
 let aggregationSource = null
 let commandPostBillboardCollection = null
 let droneTrackBillboardCollection = null
@@ -282,8 +286,12 @@
 	cockpitPrimitiveLayer.removeAll(false)
 	if (defenseZonePrimitive) cockpitPrimitiveLayer.add(defenseZonePrimitive)
 	if (defenseZoneOutlinePrimitive) cockpitPrimitiveLayer.add(defenseZoneOutlinePrimitive)
-	if (partitionPrimitive) cockpitPrimitiveLayer.add(partitionPrimitive)
-	if (partitionOutlinePrimitive) cockpitPrimitiveLayer.add(partitionOutlinePrimitive)
+	if (partitionFillPrimitives.length) {
+		partitionFillPrimitives.forEach(primitive => cockpitPrimitiveLayer.add(primitive))
+	}
+	if (partitionOutlinePrimitives.length) {
+		partitionOutlinePrimitives.forEach(primitive => cockpitPrimitiveLayer.add(primitive))
+	}
 	if (deviceRingFillPrimitives.length) {
 		deviceRingFillPrimitives.forEach(primitive => cockpitPrimitiveLayer.add(primitive))
 	}
@@ -337,13 +345,13 @@
 
 const clearPartitionEntities = () => {
 	if (!viewer) return
-	if (partitionPrimitive) {
-		removeCockpitPrimitive(partitionPrimitive)
-		partitionPrimitive = null
+	if (partitionFillPrimitives.length) {
+		partitionFillPrimitives.forEach(primitive => removeCockpitPrimitive(primitive))
+		partitionFillPrimitives = []
 	}
-	if (partitionOutlinePrimitive) {
-		removeCockpitPrimitive(partitionOutlinePrimitive)
-		partitionOutlinePrimitive = null
+	if (partitionOutlinePrimitives.length) {
+		partitionOutlinePrimitives.forEach(primitive => removeCockpitPrimitive(primitive))
+		partitionOutlinePrimitives = []
 	}
 }
 
@@ -380,8 +388,16 @@
 	detailVisible.value = visible
 	if (defenseZonePrimitive) defenseZonePrimitive.show = visible
 	if (defenseZoneOutlinePrimitive) defenseZoneOutlinePrimitive.show = visible
-	if (partitionPrimitive) partitionPrimitive.show = visible
-	if (partitionOutlinePrimitive) partitionOutlinePrimitive.show = visible
+	if (partitionFillPrimitives.length) {
+		partitionFillPrimitives.forEach(primitive => {
+			primitive.show = visible
+		})
+	}
+	if (partitionOutlinePrimitives.length) {
+		partitionOutlinePrimitives.forEach(primitive => {
+			primitive.show = visible
+		})
+	}
 	if (commandPostBillboardCollection) commandPostBillboardCollection.show = visible
 	if (deviceBillboardCollection) deviceBillboardCollection.show = visible
 	if (deviceRingFillPrimitives.length) {
@@ -791,45 +807,76 @@
 	return list.map(item => Cesium.Cartesian3.fromDegrees(item.longitude, item.latitude))
 }
 
-const buildZonePrimitives = (zones, lineColor, fillColor1, fillColor2) => {
+const elevatePositions = async (positions, height = POLYGON_HEIGHT_M) => {
+	if (!Array.isArray(positions) || !positions.length) return []
+	if (!viewer) return positions
+	const points = positions
+		.map(pos => {
+			const carto = Cesium.Cartographic.fromCartesian(pos)
+			if (!carto) return null
+			return {
+				lng: Cesium.Math.toDegrees(carto.longitude),
+				lat: Cesium.Math.toDegrees(carto.latitude),
+			}
+		})
+		.filter(Boolean)
+	if (!points.length) return positions
+	const heights = await getPointPositionsHeight(points, viewer)
+	return heights.map(item => Cesium.Cartesian3.fromDegrees(item.longitude, item.latitude, (item.ASL ?? 0) + height))
+}
+
+const getAreaTypeStyle = areaType => {
+	return AREA_TYPE_STYLE_MAP?.[String(areaType)] || DEFAULT_AREA_STYLE
+}
+
+const buildZonePrimitives = async (zones, lineColor, fillColor1, fillColor2) => {
 	if (!viewer) return { primitive: null, outlinePrimitive: null }
 	const polygonInstances = []
 	const lineInstances = []
+	const positionGroups = []
 	const texturedVertexFormat = getTexturedVertexFormat()
-		; (zones || []).forEach((zone, index) => {
+		; (zones || []).forEach(zone => {
 			if (!zone?.geom) return
 			const positions = getDefenseZonePositions(zone.geom)
 			if (!positions.length) return
-			const polygon = new Cesium.PolygonGeometry({
-				polygonHierarchy: new Cesium.PolygonHierarchy(positions),
-				vertexFormat: texturedVertexFormat,
-			})
-			polygonInstances.push(
-				new Cesium.GeometryInstance({
-					geometry: polygon,
-				})
-			)
-			const linePositions = positions.length > 1 ? [...positions, positions[0]] : positions
-			lineInstances.push(
-				new Cesium.GeometryInstance({
-					geometry: new Cesium.GroundPolylineGeometry({
-						positions: linePositions,
-						width: 2,
-					}),
-					attributes: {
-						color: Cesium.ColorGeometryInstanceAttribute.fromColor(
-							Cesium.Color.fromCssColorString(lineColor)
-						),
-					},
-				})
-			)
+			positionGroups.push(positions)
 		})
+	if (!positionGroups.length) return { primitive: null, outlinePrimitive: null }
+	const elevatedGroups = await Promise.all(positionGroups.map(group => elevatePositions(group)))
+	elevatedGroups.forEach(elevatedPositions => {
+		if (!elevatedPositions.length) return
+		const polygon = new Cesium.PolygonGeometry({
+			polygonHierarchy: new Cesium.PolygonHierarchy(elevatedPositions),
+			perPositionHeight: true,
+			vertexFormat: texturedVertexFormat,
+		})
+		polygonInstances.push(
+			new Cesium.GeometryInstance({
+				geometry: polygon,
+			})
+		)
+		const linePositions =
+			elevatedPositions.length > 1 ? [...elevatedPositions, elevatedPositions[0]] : elevatedPositions
+		lineInstances.push(
+			new Cesium.GeometryInstance({
+				geometry: new Cesium.PolylineGeometry({
+					positions: linePositions,
+					width: 2,
+				}),
+				attributes: {
+					color: Cesium.ColorGeometryInstanceAttribute.fromColor(
+						Cesium.Color.fromCssColorString(lineColor)
+					),
+				},
+			})
+		)
+	})
 	let primitive = null
 	if (polygonInstances.length) {
 		const baseColor1 = Cesium.Color.fromCssColorString(fillColor1)
 		const baseColor2 = Cesium.Color.fromCssColorString(fillColor2)
 		const material = createRadialGradientMaterial(baseColor1.withAlpha(0.64), baseColor2.withAlpha(0.64))
-		primitive = new Cesium.GroundPrimitive({
+		primitive = new Cesium.Primitive({
 			geometryInstances: polygonInstances,
 			appearance: new Cesium.MaterialAppearance({
 				material,
@@ -840,7 +887,7 @@
 	}
 	let outlinePrimitive = null
 	if (lineInstances.length) {
-		outlinePrimitive = new Cesium.GroundPolylinePrimitive({
+		outlinePrimitive = new Cesium.Primitive({
 			geometryInstances: lineInstances,
 			appearance: new Cesium.PolylineColorAppearance(),
 		})
@@ -849,10 +896,176 @@
 	return { primitive, outlinePrimitive }
 }
 
-const renderDefenseZones = zones => {
+const buildPartitionPrimitives = async shapes => {
+	if (!viewer) return { primitives: [], outlinePrimitives: [] }
+	const vertexFormat = getTexturedVertexFormat()
+	const groups = new Map()
+	const tasks = []
+		; (shapes || []).forEach(shape => {
+			if (!shape?.positions || shape.positions.length < 3) return
+			const outlineColor = shape.outlineColor
+			const fillColor = shape.fillColor
+			const key = `${outlineColor.toCssColorString()}|${fillColor.toCssColorString()}`
+			if (!groups.has(key)) {
+				groups.set(key, { outlineColor, fillColor, polygonInstances: [], lineInstances: [] })
+			}
+			const group = groups.get(key)
+			const positions = shape.positions
+			tasks.push(
+				elevatePositions(positions).then(elevatedPositions => {
+					if (!elevatedPositions.length) return
+					const polygon = new Cesium.PolygonGeometry({
+						polygonHierarchy: new Cesium.PolygonHierarchy(elevatedPositions),
+						perPositionHeight: true,
+						vertexFormat,
+					})
+					group.polygonInstances.push(
+						new Cesium.GeometryInstance({
+							geometry: polygon,
+						})
+					)
+					const linePositions =
+						elevatedPositions.length > 1
+							? [...elevatedPositions, elevatedPositions[0]]
+							: elevatedPositions
+					group.lineInstances.push(
+						new Cesium.GeometryInstance({
+							geometry: new Cesium.PolylineGeometry({
+								positions: linePositions,
+								width: 2,
+							}),
+							attributes: {
+								color: Cesium.ColorGeometryInstanceAttribute.fromColor(outlineColor),
+							},
+						})
+					)
+				})
+			)
+		})
+
+	if (tasks.length) await Promise.all(tasks)
+
+	const primitives = []
+	const outlinePrimitives = []
+	groups.forEach(group => {
+		if (group.polygonInstances.length) {
+			const material = createRadialGradientMaterial(group.outlineColor, group.fillColor, {
+				gamma: 1.7,
+				innerCutoff: 0,
+			})
+			const primitive = new Cesium.Primitive({
+				geometryInstances: group.polygonInstances,
+				appearance: new Cesium.MaterialAppearance({
+					material,
+					translucent: true,
+				}),
+			})
+			addCockpitPrimitive(primitive)
+			primitives.push(primitive)
+		}
+		if (group.lineInstances.length) {
+			const outlinePrimitive = new Cesium.Primitive({
+				geometryInstances: group.lineInstances,
+				appearance: new Cesium.PolylineColorAppearance(),
+			})
+			addCockpitPrimitive(outlinePrimitive)
+			outlinePrimitives.push(outlinePrimitive)
+		}
+	})
+
+	return { primitives, outlinePrimitives }
+}
+
+const parseGeomJson = geomJson => {
+	if (!geomJson) return null
+	if (typeof geomJson === 'object') return geomJson
+	if (typeof geomJson !== 'string') return null
+	const trimmed = geomJson.trim()
+	if (!trimmed) return null
+	try {
+		return JSON.parse(trimmed)
+	} catch (error) {}
+	return null
+}
+
+const normalizeShapePoint = point => {
+	if (!point) return null
+	const lng = point?.lng ?? point?.longitude
+	const lat = point?.lat ?? point?.latitude
+	const height = Number.isFinite(Number(point?.height)) ? Number(point.height) : 0
+	if (!Number.isFinite(Number(lng)) || !Number.isFinite(Number(lat))) return null
+	return { lng: Number(lng), lat: Number(lat), height }
+}
+
+const buildShapePositions = (points = []) => {
+	const normalized = points.map(normalizeShapePoint).filter(Boolean)
+	return normalized.map(point => Cesium.Cartesian3.fromDegrees(point.lng, point.lat, point.height))
+}
+
+const getShapeDisplayPoints = shape => {
+	if (Array.isArray(shape?.displayPoints) && shape.displayPoints.length) {
+		return shape.displayPoints
+	}
+	return shape?.points || []
+}
+
+const resolvePartitionShapes = areas => {
+	const shapes = []
+		; (areas || []).forEach(area => {
+			const extList = Array.isArray(area?.fwAreaDivideExtList) ? area.fwAreaDivideExtList : []
+			extList.forEach((item, index) => {
+				const isShapePayload = item?.drawType || item?.points
+				const parsed = isShapePayload ? item : parseGeomJson(item?.geomJson)
+				if (!parsed) return
+				const shape = {
+					id: parsed?.id || `shape_${Date.now()}_${index}_${Math.random().toString(16).slice(2, 6)}`,
+					drawType: parsed?.drawType ?? 'polygon',
+					areaType: parsed?.areaType ?? item?.areaTypeKey ?? item?.areaType ?? '',
+					points: Array.isArray(parsed?.points) ? parsed.points : [],
+					displayPoints: Array.isArray(parsed?.displayPoints) ? parsed.displayPoints : null,
+					meta: parsed?.meta ?? null,
+				}
+				if (shape.drawType === 'buffer' && shape.meta?.bufferRadii?.length && shape.meta?.center) {
+					const center = shape.meta.center
+					const centerCartesian = Cesium.Cartesian3.fromDegrees(
+						center.lng,
+						center.lat,
+						center.height || 0
+					)
+					const radii = shape.meta.bufferRadii
+						.map(radius => Number(radius))
+						.filter(radius => Number.isFinite(radius) && radius > 0)
+					radii.forEach((radius, levelIndex) => {
+						const positions = buildEllipsePositions(centerCartesian, radius, radius)
+					const style = BUFFER_LEVEL_STYLES[levelIndex] || BUFFER_LEVEL_STYLES[BUFFER_LEVEL_STYLES.length - 1]
+						if (positions.length >= 3) {
+							shapes.push({
+								positions,
+								fillColor: style.fill,
+								outlineColor: style.outline,
+							})
+						}
+					})
+					return
+				}
+				const positions = buildShapePositions(getShapeDisplayPoints(shape))
+				if (positions.length >= 3) {
+					const style = getAreaTypeStyle(shape.areaType)
+					shapes.push({
+						positions,
+						fillColor: style.fill,
+						outlineColor: style.outline,
+					})
+				}
+			})
+		})
+	return shapes
+}
+
+const renderDefenseZones = async zones => {
 	if (!viewer) return
 	clearDefenseZoneEntities()
-	const result = buildZonePrimitives(zones, '#72F3FF', '#72F3FF', '#0A7C88')
+	const result = await buildZonePrimitives(zones, '#72F3FF', '#72F3FF', '#0A7C88')
 	defenseZonePrimitive = result.primitive
 	defenseZoneOutlinePrimitive = result.outlinePrimitive
 	if (defenseZonePrimitive) defenseZonePrimitive.show = detailVisible.value
@@ -860,14 +1073,23 @@
 	reorderCockpitPrimitives()
 }
 
-const renderPartitions = zones => {
+const renderPartitions = async zones => {
 	if (!viewer) return
 	clearPartitionEntities()
-	const result = buildZonePrimitives(zones, '#FFD772', '#FFD772', '#A86B00')
-	partitionPrimitive = result.primitive
-	partitionOutlinePrimitive = result.outlinePrimitive
-	if (partitionPrimitive) partitionPrimitive.show = detailVisible.value
-	if (partitionOutlinePrimitive) partitionOutlinePrimitive.show = detailVisible.value
+	const shapes = resolvePartitionShapes(zones)
+	const result = await buildPartitionPrimitives(shapes)
+	partitionFillPrimitives = result.primitives
+	partitionOutlinePrimitives = result.outlinePrimitives
+	if (partitionFillPrimitives.length) {
+		partitionFillPrimitives.forEach(primitive => {
+			primitive.show = detailVisible.value
+		})
+	}
+	if (partitionOutlinePrimitives.length) {
+		partitionOutlinePrimitives.forEach(primitive => {
+			primitive.show = detailVisible.value
+		})
+	}
 	reorderCockpitPrimitives()
 }
 
@@ -875,19 +1097,19 @@
 	if (!viewer) return
 	try {
 		const res = await fwDefenseZonePageApi({ current: 1, size: DEFAULT_ZONE_PAGE_SIZE })
-		renderDefenseZones(res?.data?.data?.records ?? [])
+		await renderDefenseZones(res?.data?.data?.records ?? [])
 	} catch (error) {
-		renderDefenseZones([])
+		await renderDefenseZones([])
 	}
 }
 
 const loadPartitions = async () => {
 	if (!viewer) return
 	try {
-		const res = await fwAreaDividePageApi({ current: 1, size: DEFAULT_ZONE_PAGE_SIZE })
-		renderPartitions(res?.data?.data?.records ?? [])
+		const res = await fwAreaDivideListApi()
+		await renderPartitions(res?.data?.data ?? [])
 	} catch (error) {
-		renderPartitions([])
+		await renderPartitions([])
 	}
 }
 

--
Gitblit v1.9.3