From 48d9fca88c60c17d9a591b311a0bd5dc61d1462d Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Thu, 05 Feb 2026 10:31:55 +0800
Subject: [PATCH] feat:多边形绘制优化,移动端webview存储优化

---
 applications/drone-command/src/utils/cesium/shapeTools/edit/EditPolygonTool.js |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/applications/drone-command/src/utils/cesium/shapeTools/edit/EditPolygonTool.js b/applications/drone-command/src/utils/cesium/shapeTools/edit/EditPolygonTool.js
index e0a09df..462d805 100644
--- a/applications/drone-command/src/utils/cesium/shapeTools/edit/EditPolygonTool.js
+++ b/applications/drone-command/src/utils/cesium/shapeTools/edit/EditPolygonTool.js
@@ -3,6 +3,7 @@
 import { ToolBase } from '../ToolBase'
 
 const POINT_ENTITY_NAME = 'edit-polygon-point'
+const MIDPOINT_ENTITY_NAME = 'edit-polygon-midpoint'
 const DEFAULT_STYLE = {
 	fill: Cesium.Color.fromBytes(45, 140, 240, 99),
 	outline: Cesium.Color.fromBytes(45, 140, 240, 255),
@@ -57,7 +58,20 @@
 
 	handleLeftDown(click) {
 		const pickedEntity = this.viewer.scene.pick(click.position)?.id
-		if (!pickedEntity || pickedEntity.name !== POINT_ENTITY_NAME) return
+		if (!pickedEntity) return
+		if (pickedEntity.name === MIDPOINT_ENTITY_NAME) {
+			const leftIndex = pickedEntity.customData?.leftIndex
+			const rightIndex = pickedEntity.customData?.rightIndex
+			if (typeof leftIndex !== 'number' || typeof rightIndex !== 'number') return
+			const midpoint = this.getMidpointPosition(leftIndex, rightIndex)
+			this.positions.splice(rightIndex, 0, midpoint)
+			this.rebuildPointEntities()
+			this.isDragging = true
+			this.draggedIndex = rightIndex
+			this.disableMapControl()
+			return
+		}
+		if (pickedEntity.name !== POINT_ENTITY_NAME) return
 		const index = pickedEntity.customData?.index
 		if (typeof index !== 'number') return
 		this.isDragging = true
@@ -131,7 +145,7 @@
 	rebuildPointEntities() {
 		this.dataSource.entities.values
 			.slice()
-			.filter(entity => entity?.name === POINT_ENTITY_NAME)
+			.filter(entity => entity?.name === POINT_ENTITY_NAME || entity?.name === MIDPOINT_ENTITY_NAME)
 			.forEach(entity => this.dataSource.entities.remove(entity))
 
 		this.positions.forEach((position, index) => {
@@ -151,6 +165,30 @@
 				},
 			})
 		})
+
+		const count = this.positions.length
+		if (count < 2) return
+		const segmentCount = count === 2 ? 1 : count
+		for (let i = 0; i < segmentCount; i += 1) {
+			const leftIndex = i
+			const rightIndex = i + 1 < count ? i + 1 : 0
+			this.dataSource.entities.add({
+				name: MIDPOINT_ENTITY_NAME,
+				position: new Cesium.CallbackProperty(() => this.getMidpointPosition(leftIndex, rightIndex), false),
+				point: {
+					pixelSize: 8,
+					color: Cesium.Color.WHITE.withAlpha(0.6),
+					outlineColor: this.style.outline.withAlpha(0.6),
+					outlineWidth: 2,
+					heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
+					disableDepthTestDistance: Number.POSITIVE_INFINITY,
+				},
+				customData: {
+					leftIndex,
+					rightIndex,
+				},
+			})
+		}
 	}
 
 	getPositions() {
@@ -164,6 +202,13 @@
 		return scene.camera.pickEllipsoid(screenPosition, scene.globe.ellipsoid)
 	}
 
+	getMidpointPosition(leftIndex, rightIndex) {
+		const left = this.positions[leftIndex]
+		const right = this.positions[rightIndex]
+		if (!left || !right) return left || right
+		return Cesium.Cartesian3.midpoint(left, right, new Cesium.Cartesian3())
+	}
+
 	setStyle(style) {
 		this.style = resolveStyle(style)
 		if (this.polygonEntity?.polygon) {

--
Gitblit v1.9.3