吉安感知网项目-前端
shuishen
2026-01-28 20af1273bd4ae8ae061a92768e14f95d52721e6c
applications/drone-command/src/views/areaManage/partition/shapeTools/draw/DrawPolygonTool.js
@@ -3,9 +3,17 @@
import { ToolBase } from '../ToolBase'
const POINT_ENTITY_NAME = 'draw-polygon-point'
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 DrawPolygonTool extends ToolBase {
   constructor(viewer) {
   constructor(viewer, options = {}) {
      super(viewer)
      this.tooltip = new MapTooltip(viewer)
      this.dataSource = null
@@ -15,6 +23,7 @@
      this.floatPosition = null
      this.isDrawing = false
      this.lastMousePosition = null
      this.style = resolveStyle(options?.style)
   }
   start() {
@@ -120,7 +129,7 @@
               () => new Cesium.PolygonHierarchy(getPreviewPositions()),
               false
            ),
            material: Cesium.Color.fromBytes(45, 140, 240, 99),
            material: this.style.fill,
            outline: false,
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            show: new Cesium.CallbackProperty(() => getPreviewPositions().length >= 3, false),
@@ -139,7 +148,7 @@
            }, false),
            clampToGround: true,
            width: 2,
            material: Cesium.Color.fromBytes(45, 140, 240, 255),
            material: this.style.outline,
            show: new Cesium.CallbackProperty(() => getPreviewPositions().length >= 2, false),
         },
      })
@@ -158,7 +167,7 @@
            point: {
               pixelSize: 12,
               color: Cesium.Color.WHITE,
               outlineColor: Cesium.Color.fromBytes(45, 140, 240, 255),
               outlineColor: this.style.outline,
               outlineWidth: 2,
               heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
               disableDepthTestDistance: Number.POSITIVE_INFINITY,
@@ -179,6 +188,25 @@
      this.clearPreviewEntities()
   }
   setStyle(style) {
      this.style = resolveStyle(style)
      if (this.polygonEntity?.polygon) {
         this.polygonEntity.polygon.material = this.style.fill
      }
      if (this.polylineEntity?.polyline) {
         this.polylineEntity.polyline.material = this.style.outline
      }
      if (this.dataSource) {
         this.dataSource.entities.values
            .filter(entity => entity?.name === POINT_ENTITY_NAME)
            .forEach(entity => {
               if (entity?.point) {
                  entity.point.outlineColor = this.style.outline
               }
            })
      }
   }
   clearPreviewEntities() {
      if (!this.dataSource) return
      this.dataSource.entities.removeAll()