一些技术路线测试,增加git,方便代码还原
shuishen
2025-11-22 efc256c6c311b84b40184109750ea2e5c216cd5b
feat:中心控制器的显示控制。
3 files modified
108 ■■■■■ changed files
js/modules/axis-manager.js 53 ●●●●● patch | view | raw | blame | history
js/modules/edit-manager.js 35 ●●●● patch | view | raw | blame | history
video-中心控制器备份.html 20 ●●●●● patch | view | raw | blame | history
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) {
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)
video-中心控制器备份.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)
                    // 交互:悬停高亮与轴拖拽,拖拽结束重算航线