From 233e4fc4f35bd00a36ee34a7fbf5e47b41db26db Mon Sep 17 00:00:00 2001
From: chenyao <1219716595@qq.com>
Date: Mon, 17 Nov 2025 09:54:44 +0800
Subject: [PATCH] feat:更新初始化地形
---
src/views/layerManagement/components/utils.js | 82 +++++++++++++++++-----------------------
1 files changed, 35 insertions(+), 47 deletions(-)
diff --git a/src/views/layerManagement/components/utils.js b/src/views/layerManagement/components/utils.js
index fbcb033..7001570 100644
--- a/src/views/layerManagement/components/utils.js
+++ b/src/views/layerManagement/components/utils.js
@@ -14,6 +14,8 @@
*/
export class DrawPolygon {
constructor() {
+ // 是否绘制
+ this.whetherToDraw =false
// 图斑预览模式标记
this.isPureSpotPreview = false
// 是否删除测区
@@ -61,6 +63,7 @@
this.delPoint = this.delPoint.bind(this)
// 外部订阅者
this.listeners = []
+
}
// 实体命名常量
@@ -96,6 +99,10 @@
editThePatch(data) {
this.isPreviewMode = data
}
+ // 绘制
+ drawTheArea(data){
+ this.whetherToDraw = data
+ }
// 删除测区
deleteTheArea(data) {
this.isDeleteTheArea = data
@@ -103,6 +110,12 @@
// 开始绘制
startDrawing() {
+ if (!this.whetherToDraw) {
+
+ return;
+ }
+
+
this.drawingMode = true
this.curPolygon = new Cesium.PolygonHierarchy()
@@ -167,35 +180,7 @@
}
- // 清除不在范围内的点
- removeLastInvalidPoint() {
- const posLen = this.curPolygon.positions.length
- if (posLen === 0) return
- let targetPointId = ''
- let removeCount = 0
-
- if (posLen === 2) {
- removeCount = 2
- targetPointId = `${DrawPolygon.ENTITY_NAMES.POINT_ID_PREFIX}0`
- } else if (posLen > 2) {
- removeCount = 1
- const pointIndex = posLen - 2
- targetPointId = `${DrawPolygon.ENTITY_NAMES.POINT_ID_PREFIX}${pointIndex}`
- }
-
- this.curPolygon.positions.splice(posLen - removeCount, removeCount)
-
- const invalidPoint = this.editPolygonPointDataSource.entities.getById(targetPointId)
- if (invalidPoint) {
- this.editPolygonPointDataSource.entities.remove(invalidPoint)
- }
-
- if (this.curPolygon.positions.length === 0 && this.polygonEntity) {
- this.editPolygonDataSource.entities.remove(this.polygonEntity)
- this.polygonEntity = null
- }
- }
// 添加一个点
addPosition(position, isAdd = true) {
// 第一个点要重复压入一次,形成动态绘制效果
@@ -277,7 +262,7 @@
// 编辑模式下,拖拽点实时更新
if (this.editingMode && this.draggedEntity?.customData) {
this.draggedEntity.position = cartesian
- this.curPolygon.positions[this.draggedEntity?.customData.ind] = cartesian
+ this.curPolygon.positions[this.draggedEntity?.customData.ind] = cartesian
}
// 绘制模式下,实时更新最后一个点
@@ -308,23 +293,25 @@
// 鼠标左键点击
handleLeftClick(click) {
this.removeMenuPopup()
-
const pickedAllEntity = this.viewer.scene.drillPick(click.position).filter(i => i.id)
-
const isPolygonPoint = pickedAllEntity.find(i => i.id.name === DrawPolygon.ENTITY_NAMES.POINT)
const isPolygon = pickedAllEntity.find(i => i.id.name === DrawPolygon.ENTITY_NAMES.POLYGON)
-
-
-
+ if (this.drawingMode && !this.whetherToDraw) {
+
+ return; // 阻断后续绘制逻辑
+ }
// 如果不是绘制模式
if (!this.drawingMode) {
if (!isPolygon) {
+
+
this.editingMode = false
this.editPolygonPointDataSource.entities.show = false
return
}
if (isPolygon) {
+
this.editingMode = true
this.editPolygonPointDataSource.entities.show = true
}
@@ -434,12 +421,7 @@
this.notify('getPolygonPositions', [])
this.startDrawing()
}
- // 删除图斑
- delSpot() {
- this.removeEntities()
- this.isPreviewMode = true
- this.startDrawing()
- }
+
// 删除端点
delPoint() {
if (this.curPolygon.positions.length <= 3) {
@@ -544,16 +526,19 @@
// 初始化已有多边形
initPolygon(viewer, positions, isPurePreview = false) {
this.initHandler(viewer)
- this.isPureSpotPreview = isPurePreview
- this.startDrawing()
+
+ if (this.whetherToDraw) {
+ this.startDrawing();
+ } else {
+ // 新增:不允许绘制时,确保绘制模式为 false,避免误触发
+ this.drawingMode = false;
+
+ }
let newPosition = positions.map(item => {
return Cesium.Cartesian3.fromDegrees(Number(item.lng), Number(item.lat), Number(item.height))
})
- // 预览航线的时候调用
- if (!this.isPureSpotPreview) {
- this.notify('getPolygonPositions', newPosition)
- }
+
newPosition.forEach(item => {
this.addPosition(item, false)
@@ -577,7 +562,10 @@
// 初始化事件处理器
initHandler(viewer) {
this.viewer = viewer
- this.startDrawing()
+
+ if(this.whetherToDraw){
+ this.startDrawing()
+ }
if (!this.handler) {
this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
--
Gitblit v1.9.3