From efc256c6c311b84b40184109750ea2e5c216cd5b Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Sat, 22 Nov 2025 14:33:21 +0800
Subject: [PATCH] feat:中心控制器的显示控制。
---
js/modules/edit-manager.js | 35 ++++++++++++++---
js/modules/axis-manager.js | 53 +++++++++++++++++++++++++-
video-中心控制器备份.html | 20 ++++++++++
3 files changed, 100 insertions(+), 8 deletions(-)
diff --git a/js/modules/axis-manager.js b/js/modules/axis-manager.js
index 0d75cfc..8bec80a 100644
--- a/js/modules/axis-manager.js
+++ b/js/modules/axis-manager.js
@@ -34,6 +34,8 @@
this.centerVectorZC = null
this.dashLineList = []
this.flip = { x: false, y: false, z: false }
+ this.editingEnabled = false
+ this.interaction = { type: null, axis: null }
this.planeCtx = { activeShape: null, polygonPositionList: [], centerPoint: null }
this.axisModelUris = { axisX: 'gltf/green-arrows.gltf', axisY: 'gltf/red-arrows.gltf', axisZ: 'gltf/blue-arrows.gltf' }
@@ -51,6 +53,28 @@
}
}
+ setControllerVisibility (show) {
+ const s = !!show
+ if (this.axisEntyX) this.axisEntyX.show = s
+ if (this.axisEntyY) this.axisEntyY.show = s
+ if (this.axisEntyZ) this.axisEntyZ.show = s
+ if (this.sphereEntyX) this.sphereEntyX.show = s
+ if (this.sphereEntyY) this.sphereEntyY.show = s
+ if (this.sphereEntyZ) this.sphereEntyZ.show = s
+ if (this.overlayModels.axisX) this.overlayModels.axisX.show = s
+ if (this.overlayModels.axisY) this.overlayModels.axisY.show = s
+ if (this.overlayModels.axisZ) this.overlayModels.axisZ.show = s
+ if (this.overlayModels.sphereX) this.overlayModels.sphereX.show = s
+ if (this.overlayModels.sphereY) this.overlayModels.sphereY.show = s
+ if (this.overlayModels.sphereZ) this.overlayModels.sphereZ.show = s
+ if (!s) this.dashLineList.forEach(ele => { ele.show = false })
+ }
+
+ setEditingEnabled (flag) {
+ this.editingEnabled = !!flag
+ this.setControllerVisibility(this.editingEnabled)
+ }
+
/**
* 注入当前平面上下文(面实体、顶点列表、中心点)
* @param {{activeShape:Cesium.Entity,polygonPositionList:Cesium.Cartesian3[],centerPoint:Cesium.Cartesian3}} ctx 上下文
@@ -58,6 +82,7 @@
setPlaneContext (ctx) {
this.planeCtx = ctx
this.centerPoint = ctx.centerPoint
+ this.setEditingEnabled(true)
}
/**
@@ -192,6 +217,11 @@
this.centerVectorXC = g.centerVectorXC
this.centerVectorYC = g.centerVectorYC
this.centerVectorZC = g.centerVectorZC
+ if (this.interaction && this.interaction.type === 'rotation' && this.interaction.axis) {
+ this.setRotationAxisFocus(this.interaction.axis)
+ } else {
+ this.setControllerVisibility(this.editingEnabled)
+ }
}
/**
@@ -332,6 +362,7 @@
let translationController = this._translationController()
masterController.setInputAction((e) => {
+ if (!this.editingEnabled) return
const results = viewer.scene.drillPick(e.position)
let hit = null
let id = null
@@ -354,9 +385,9 @@
let isTranslation = false
if (id.slice(0, 6) === 'sphere') {
- if (rotationController.startRotation(hit, this.centerPoint)) { isRotation = true; this._setDragRotationFocus(rotationController.state.currentAxis) }
+ if (rotationController.startRotation(hit, this.centerPoint)) { isRotation = true; this.interaction = { type: 'rotation', axis: rotationController.state.currentAxis }; this._setDragRotationFocus(rotationController.state.currentAxis) }
} else if (id.slice(0, 4) === 'axis') {
- if (translationController.startTranslation(hit, this.centerPoint)) { isTranslation = true; translationController.state.lastMousePosition = new Cesium.Cartesian2(e.position.x, e.position.y); this._setDragTranslationHighlight(translationController.state.currentAxis) }
+ if (translationController.startTranslation(hit, this.centerPoint)) { isTranslation = true; this.interaction = { type: 'translation', axis: translationController.state.currentAxis }; translationController.state.lastMousePosition = new Cesium.Cartesian2(e.position.x, e.position.y); this._setDragTranslationHighlight(translationController.state.currentAxis) }
}
if (!isRotation && !isTranslation) return
this.setDistanceLabelsVisibility(false)
@@ -402,10 +433,12 @@
this.bindHover()
if (isRotation) rotationController.endRotation()
if (isTranslation) translationController.endTranslation()
+ this.interaction = { type: null, axis: null }
if (typeof onUpdate === 'function') onUpdate(this.planeCtx.polygonPositionList)
this.createAxisEntity(...this.planeCtx.polygonPositionList)
this.updateDistanceLabels()
this.setDistanceLabelsVisibility(true)
+ this.setControllerVisibility(this.editingEnabled)
}, Cesium.ScreenSpaceEventType.LEFT_UP)
}, Cesium.ScreenSpaceEventType.LEFT_DOWN)
}
@@ -465,6 +498,22 @@
bindHover () {
const handler = this.eventHub.get('hover')
handler.setInputAction((arg) => {
+ if (!this.editingEnabled) {
+ this.axisEntyZ && (this.axisEntyZ.model.silhouetteSize = new Cesium.CallbackProperty(() => 0, false))
+ this.axisEntyX && (this.axisEntyX.model.silhouetteSize = new Cesium.CallbackProperty(() => 0, false))
+ this.axisEntyY && (this.axisEntyY.model.silhouetteSize = new Cesium.CallbackProperty(() => 0, false))
+ if (this.overlayModels.axisZ) this.overlayModels.axisZ.silhouetteSize = 0
+ if (this.overlayModels.axisX) this.overlayModels.axisX.silhouetteSize = 0
+ if (this.overlayModels.axisY) this.overlayModels.axisY.silhouetteSize = 0
+ this.sphereEntyX && (this.sphereEntyX.model.silhouetteSize = new Cesium.CallbackProperty(() => 0, false))
+ this.sphereEntyY && (this.sphereEntyY.model.silhouetteSize = new Cesium.CallbackProperty(() => 0, false))
+ this.sphereEntyZ && (this.sphereEntyZ.model.silhouetteSize = new Cesium.CallbackProperty(() => 0, false))
+ if (this.overlayModels.sphereX) this.overlayModels.sphereX.silhouetteSize = 0
+ if (this.overlayModels.sphereY) this.overlayModels.sphereY.silhouetteSize = 0
+ if (this.overlayModels.sphereZ) this.overlayModels.sphereZ.silhouetteSize = 0
+ this.dashLineList.forEach(ele => { ele.show = false })
+ return
+ }
const results = this.viewer.scene.drillPick(arg.endPosition)
let id = null
if (Array.isArray(results) && results.length > 0) {
diff --git a/js/modules/edit-manager.js b/js/modules/edit-manager.js
index 63faffc..686a72e 100644
--- a/js/modules/edit-manager.js
+++ b/js/modules/edit-manager.js
@@ -49,17 +49,40 @@
const editTriggerHandler = this.eventHub.get('editTrigger')
const editDragHandler = this.eventHub.get('editDrag')
- editTriggerHandler.setInputAction((click) => {
- const pickC = viewer.scene.pick(click.position)
+ isActivateEditRef.value = true
+ if (axisManager && typeof axisManager.setEditingEnabled === 'function') axisManager.setEditingEnabled(true)
+
+ const toggleHandler = this.eventHub.get('editModeToggle')
+ toggleHandler.setInputAction((click) => {
+ const results = viewer.scene.drillPick(click.position)
+ let hitPolygon = false
+ let hitController = false
+ if (Array.isArray(results) && results.length > 0) {
+ for (let k = 0; k < results.length; k++) {
+ const rid = (results[k] && (results[k].id?.id || results[k].id || results[k].primitive?.id))
+ if (!rid) continue
+ const s = String(rid)
+ if (s === 'polygon') { hitPolygon = true; break }
+ if (s.slice(0, 6) === 'sphere' || s.slice(0, 4) === 'axis') { hitController = true; break }
+ }
+ }
+ if (hitController) return
+ if (hitPolygon) { isActivateEditRef.value = true; if (axisManager && axisManager.setEditingEnabled) axisManager.setEditingEnabled(true); return }
+ isActivateEditRef.value = false
this.entityFactory.removeEntityLikeName('polygonEditPoint')
- let isEdit = false
- if (Cesium.defined(pickC) && pickC.id) { } else { isEdit = false }
- if (!isEdit) return
+ if (axisManager && axisManager.setEditingEnabled) axisManager.setEditingEnabled(false)
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
+
+ editTriggerHandler.setInputAction((click) => {
+ if (!isActivateEditRef.value) return
+ const pickC = viewer.scene.pick(click.position)
+ const rid = pickC && (pickC.id?.id || pickC.id || pickC.primitive?.id)
+ if (String(rid) !== 'polygon') return
+ this.entityFactory.removeEntityLikeName('polygonEditPoint')
const positions = polygonPositionListRef.value
positions.forEach((ele, index) => {
viewer.entities.add({ name: 'polygonEditPoint', id: 'point' + index, position: ele, point: { color: new Cesium.Color(0, 1, 1, 0.9), pixelSize: 10 } })
})
- isActivateEditRef.value = true
editDragHandler.setInputAction((e) => {
let center, centerVector
const pick = viewer.scene.pick(e.position)
diff --git "a/video-\344\270\255\345\277\203\346\216\247\345\210\266\345\231\250\345\244\207\344\273\275.html" "b/video-\344\270\255\345\277\203\346\216\247\345\210\266\345\231\250\345\244\207\344\273\275.html"
index 3739b90..4e6497e 100644
--- "a/video-\344\270\255\345\277\203\346\216\247\345\210\266\345\231\250\345\244\207\344\273\275.html"
+++ "b/video-\344\270\255\345\277\203\346\216\247\345\210\266\345\231\250\345\244\207\344\273\275.html"
@@ -487,6 +487,26 @@
// 坐标轴控制器:创建并与面绑定上下文
axisManager.createAxisEntity(p0, p1, p2, p3)
axisManager.setPlaneContext({ activeShape, polygonPositionList: polygon, centerPoint: axisManager.centerPoint })
+ const polygonPositionListRef = { value: polygon }
+ const activeShapeRef = { value: activeShape }
+ const centerPointRef = { value: axisManager.centerPoint }
+ const labels = {
+ d01: viewer.entities.getById('distanceLabel01'),
+ d12: viewer.entities.getById('distanceLabel12'),
+ d23: viewer.entities.getById('distanceLabel23'),
+ d34: viewer.entities.getById('distanceLabel34')
+ }
+ const isActivateEditRef = { value: true }
+ editManager.register(
+ polygonPositionListRef,
+ activeShapeRef,
+ centerPointRef,
+ axisManager,
+ labelManager.formatDistance.bind(labelManager),
+ labels,
+ faceAirLineTool,
+ isActivateEditRef
+ )
// 初次生成航线(绘制完成)
faceAirLineTool.setPositionData(polygon, false, true)
// 交互:悬停高亮与轴拖拽,拖拽结束重算航线
--
Gitblit v1.9.3