吉安感知网项目-前端
shuishen
2026-01-31 f3e09a76a7f5147072374b80285901ff69ee2cfe
packages/utils/map/DrawPolygon.js
File was renamed from applications/task-work-order/src/utils/cesium/DrawPolygon.js
@@ -1,9 +1,8 @@
import * as Cesium from 'cesium'
import * as turf from '@turf/turf'
import { boxTransformScale } from '@/utils/turfFunc'
import { ElMessage } from 'element-plus'
import { getPointPositionsHeight } from '@/utils/cesium/mapUtil'
import { flyVisual } from '@ztzf/utils'
import { flyVisual, getPointPositionsHeight } from './index'
import { MapTooltip } from './MapTooltip'
/**
 * 多边形绘制与编辑工具类
@@ -65,6 +64,8 @@
      this.delPoint = this.delPoint.bind(this)
      // 外部订阅者
      this.listeners = []
      // 绘制提示 tooltip
      this.drawingTooltip = null
   }
   // 实体命名常量
@@ -433,6 +434,11 @@
      const cartesian = this.viewer.scene.pickPosition(movement.endPosition)
      if (!cartesian) return
      // 更新绘制提示 tooltip 位置
      if (this.drawingMode && this.drawingTooltip) {
         this.drawingTooltip.move(movement.endPosition)
      }
      // 编辑模式下,拖拽点实时更新
      if (this.editingMode && this.draggedEntity?.customData) {
         this.draggedEntity.position = cartesian
@@ -581,6 +587,11 @@
   finishDrawing() {
      this.curPolygon.positions.pop()
      // 隐藏绘制提示
      if (this.drawingTooltip) {
         this.drawingTooltip.hide()
      }
      if (this.curPolygon.positions.length >= 3) {
         this.drawingMode = false
         this.editingMode = true
@@ -609,6 +620,11 @@
      this.removeMenuPopup()
      this.notify('getPolygonPositions', [])
      this.startDrawing()
      // 重新显示绘制提示
      if (this.drawingTooltip) {
         this.drawingTooltip.show('左键点击绘制,双击结束绘制')
      }
   }
   // 删除图斑
   delSpot() {
@@ -727,6 +743,15 @@
         this.addPosition(item, false)
      })
      const boxTransformScale = (data, multiple = 3) => {
         const line = turf.lineString(data)
         const bbox = turf.bbox(line)
         const bboxPolygon = turf.bboxPolygon(bbox)
         const scaledPolygon = turf.transformScale(bboxPolygon, multiple)
         return turf.bbox(scaledPolygon)
      }
      // 视角飞入区域
      const newBox = boxTransformScale(
         positions.map(item => [item.lng, item.lat]),
@@ -752,6 +777,12 @@
   initHandler(viewer) {
      this.viewer = viewer
      this.startDrawing()
      // 初始化绘制提示 tooltip
      if (!this.drawingTooltip) {
         this.drawingTooltip = new MapTooltip(viewer)
         this.drawingTooltip.show('左键点击绘制,双击结束绘制')
      }
      if (!this.handler) {
         this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
@@ -800,5 +831,11 @@
      this.removeEntities()
      this.removeHandler()
      this.enableMapControl()
      // 销毁绘制提示 tooltip
      if (this.drawingTooltip) {
         this.drawingTooltip.destroy()
         this.drawingTooltip = null
      }
   }
}