吉安感知网项目-前端
张含笑
2026-01-29 9fb4de853fc8aab2000f312ba2b8907e3dc9a61d
applications/drone-command/src/views/areaManage/partition/shapeTools/edit/EditRectangleTool.js
@@ -3,6 +3,15 @@
import { ToolBase } from '../ToolBase'
import { getBoundsFromLngLats, rectanglePositionsFromBounds } from '../shapeUtils'
const DEFAULT_STYLE = {
   fill: Cesium.Color.fromBytes(45, 140, 240, 99),
   outline: Cesium.Color.fromBytes(45, 140, 240, 255),
}
const resolveStyle = style => ({
   fill: style?.fill || DEFAULT_STYLE.fill,
   outline: style?.outline || DEFAULT_STYLE.outline,
})
const normalizePoints = points =>
   (points || []).map(point => ({
      lng: point.lng ?? point.longitude,
@@ -10,7 +19,7 @@
   }))
export class EditRectangleTool extends ToolBase {
   constructor(viewer) {
   constructor(viewer, options = {}) {
      super(viewer)
      this.tooltip = new MapTooltip(viewer)
      this.dataSource = null
@@ -20,6 +29,7 @@
      this.cornerEntities = []
      this.dragIndex = null
      this.fixedCorner = null
      this.style = resolveStyle(options?.style)
   }
   start(points = []) {
@@ -81,7 +91,7 @@
      this.rectangleEntity = this.dataSource.entities.add({
         polygon: {
            hierarchy,
            material: Cesium.Color.fromBytes(45, 140, 240, 99),
            material: this.style.fill,
            outline: false,
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
         },
@@ -94,7 +104,7 @@
            }, false),
            clampToGround: true,
            width: 2,
            material: Cesium.Color.fromBytes(45, 140, 240, 255),
            material: this.style.outline,
         },
      })
      this.createCorners()
@@ -141,6 +151,16 @@
      return scene.camera.pickEllipsoid(screenPosition, scene.globe.ellipsoid)
   }
   setStyle(style) {
      this.style = resolveStyle(style)
      if (this.rectangleEntity?.polygon) {
         this.rectangleEntity.polygon.material = this.style.fill
      }
      if (this.outlineEntity?.polyline) {
         this.outlineEntity.polyline.material = this.style.outline
      }
   }
   disableMapControl() {
      const controller = this.viewer.scene.screenSpaceCameraController
      controller.enableRotate = false