吉安感知网项目-前端
shuishen
2 days ago 6e88705bd5b443a259b24c17c8a299765d059d96
applications/drone-command/src/utils/cesium/shapeTools/edit/EditBufferCircleTool.js
@@ -1,7 +1,13 @@
import * as Cesium from 'cesium'
import { MapTooltip } from '@ztzf/utils'
import { ToolBase } from '../ToolBase'
import { buildEllipsePositions, cartesianToLocal } from '../shapeUtils'
import {
   buildEllipsePositions,
   cartesianToLocal,
   formatBufferRadius,
   getBufferRadiusLabelStyle,
   getBufferRadiusPoint,
} from '../shapeUtils'
const normalizePoints = points =>
   (points || []).map(point => ({
@@ -49,6 +55,9 @@
      this.radiusLevel1Entity = null
      this.radiusLevel2Entity = null
      this.radiusLevel3Entity = null
      this.radiusLevel1LabelEntity = null
      this.radiusLevel2LabelEntity = null
      this.radiusLevel3LabelEntity = null
   }
   start(data = []) {
@@ -97,7 +106,7 @@
      this.handler.setInputAction(evt => this.handleLeftDown(evt), Cesium.ScreenSpaceEventType.LEFT_DOWN)
      this.handler.setInputAction(evt => this.handleMouseMove(evt), Cesium.ScreenSpaceEventType.MOUSE_MOVE)
      this.handler.setInputAction(() => this.handleLeftUp(), Cesium.ScreenSpaceEventType.LEFT_UP)
      this.tooltip.show('拖动控制点编辑', { x: 0, y: 0 })
      this.tooltip.hide()
   }
   handleLeftDown(evt) {
@@ -111,7 +120,12 @@
   }
   handleMouseMove(evt) {
      this.tooltip.move(evt.endPosition)
      if (!this.tooltip?.isVisible) {
         this.tooltip.show('拖动控制点编辑', evt.endPosition)
      } else {
         this.tooltip.show('拖动控制点编辑')
         this.tooltip.move(evt.endPosition)
      }
      if (!this.dragType) return
      const position = this.getPositionFromScreen(evt.endPosition)
      if (!position) return
@@ -272,6 +286,10 @@
         },
         customType: 'circle-radius-3',
      })
      this.radiusLevel1LabelEntity = this.createRadiusLabelEntity(() => this.radiusLevel1)
      this.radiusLevel2LabelEntity = this.createRadiusLabelEntity(() => this.radiusLevel2)
      this.radiusLevel3LabelEntity = this.createRadiusLabelEntity(() => this.radiusLevel3)
   }
   updateRadiusPoints() {
@@ -298,14 +316,26 @@
   }
   getRadiusPoint(radius) {
      const frame = Cesium.Transforms.eastNorthUpToFixedFrame(this.centerCartesian)
      const local = new Cesium.Cartesian3(radius, 0, 0)
      return Cesium.Matrix4.multiplyByPoint(frame, local, new Cesium.Cartesian3())
      return getBufferRadiusPoint(this.centerCartesian, radius)
   }
   createRadiusLabelEntity(getRadius) {
      return this.dataSource.entities.add({
         position: new Cesium.CallbackProperty(
            () => getBufferRadiusPoint(this.centerCartesian, getRadius()),
            false
         ),
         label: {
            ...getBufferRadiusLabelStyle(),
            text: new Cesium.CallbackProperty(() => formatBufferRadius(getRadius()), false),
         },
      })
   }
   getPositionFromScreen(screenPosition) {
      const scene = this.viewer.scene
      const cartesian = scene.pickPosition(screenPosition)
      const ray = scene.camera.getPickRay(screenPosition)
      const cartesian = ray ? scene.globe.pick(ray, scene) : null
      if (cartesian) return cartesian
      return scene.camera.pickEllipsoid(screenPosition, scene.globe.ellipsoid)
   }
@@ -346,6 +376,9 @@
      this.circleLevel1OutlineEntity = null
      this.circleLevel2OutlineEntity = null
      this.circleLevel3OutlineEntity = null
      this.radiusLevel1LabelEntity = null
      this.radiusLevel2LabelEntity = null
      this.radiusLevel3LabelEntity = null
      this.dragType = null
   }
}