吉安感知网项目-前端
shuishen
2026-01-27 affb54c33083cb09cd0ef9da137b446cafdfd0fb
applications/drone-command/src/utils/cesium/DrawPolygon.js
@@ -2,7 +2,8 @@
import * as turf from '@turf/turf'
import { boxTransformScale } from '@/utils/turfFunc'
import { ElMessage } from 'element-plus'
import { flyVisual, getPointPositionsHeight } from '@/utils/cesium/mapUtil'
import { getPointPositionsHeight } from '@/utils/cesium/mapUtil'
import { flyVisual } from '@ztzf/utils'
/**
 * 多边形绘制与编辑工具类
@@ -714,7 +715,8 @@
      this.initHandler(viewer)
      this.isPureSpotPreview = isPurePreview
      this.startDrawing()
      let newPosition = positions.map(item => {
      const normalizedPositions = this.normalizePolygonPositions(positions)
      let newPosition = normalizedPositions.map(item => {
         return Cesium.Cartesian3.fromDegrees(Number(item.lng), Number(item.lat), Number(item?.height || 0))
      })
      // 预览航线的时候调用
@@ -727,17 +729,14 @@
      })
      // 视角飞入区域
      const newBox = boxTransformScale(
         positions.map(item => [item.lng, item.lat]),
         5
      )
      const newBox = boxTransformScale(normalizedPositions.map(item => [item.lng, item.lat]), 5)
      viewer.camera.flyTo({
         destination: Cesium.Rectangle.fromDegrees(...newBox),
         offset: new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-90), 0),
         duration: 0.5,
      })
      let pointList = await getPointPositionsHeight(positions, viewer)
      let pointList = await getPointPositionsHeight(normalizedPositions, viewer)
      flyVisual({ positionsData: pointList.map(item => [item.lng, item.lat, item.ASL]), viewer })
      this.drawingMode = false
@@ -745,6 +744,20 @@
      this.editPolygonPointDataSource && (this.editPolygonPointDataSource.entities.show = true)
      this.editPolygonMidPointDataSource && (this.editPolygonMidPointDataSource.entities.show = true)
      this.rebuildMidPoints()
   }
   // 规范化多边形点位:如果首尾重复,去掉末尾闭合点
   normalizePolygonPositions(positions) {
      if (!Array.isArray(positions) || positions.length < 2) return positions || []
      const first = positions[0]
      const last = positions[positions.length - 1]
      const sameLng = Number(first?.lng) === Number(last?.lng)
      const sameLat = Number(first?.lat) === Number(last?.lat)
      const sameHeight = Number(first?.height || 0) === Number(last?.height || 0)
      if (sameLng && sameLat && sameHeight) {
         return positions.slice(0, -1)
      }
      return positions
   }
   // 初始化事件处理器
@@ -785,6 +798,7 @@
            this.handler.removeInputAction(type)
         })
         this.handler.destroy()
         this.handler = null
      }
   }