吉安感知网项目-前端
shuishen
2026-01-28 20af1273bd4ae8ae061a92768e14f95d52721e6c
applications/drone-command/src/views/areaManage/partition/shapeTools/draw/DrawRectangleTool.js
@@ -3,8 +3,17 @@
import { ToolBase } from '../ToolBase'
import { getBoundsFromCartesians, 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,
})
export class DrawRectangleTool extends ToolBase {
   constructor(viewer) {
   constructor(viewer, options = {}) {
      super(viewer)
      this.tooltip = new MapTooltip(viewer)
      this.dataSource = null
@@ -13,6 +22,7 @@
      this.startPosition = null
      this.endPosition = null
      this.isDrawing = false
      this.style = resolveStyle(options?.style)
   }
   start() {
@@ -70,7 +80,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,
         },
@@ -84,7 +94,7 @@
            }, false),
            clampToGround: true,
            width: 2,
            material: Cesium.Color.fromBytes(45, 140, 240, 255),
            material: this.style.outline,
         },
      })
   }
@@ -109,6 +119,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
      }
   }
   destroy() {
      if (this.dataSource) {
         this.dataSource.entities.removeAll()