吉安感知网项目-前端
shuishen
2026-01-27 501aac6e10bc2d475852bbc59ea458c4dabed223
feat:多边形编辑优化
1 files modified
24 ■■■■ changed files
applications/drone-command/src/utils/cesium/DrawPolygon.js 24 ●●●● patch | view | raw | blame | history
applications/drone-command/src/utils/cesium/DrawPolygon.js
@@ -715,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))
        })
        // 预览航线的时候调用
@@ -728,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
@@ -748,6 +746,20 @@
        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
    }
    // 初始化事件处理器
    initHandler(viewer) {
        this.viewer = viewer