zhongrj
2025-03-28 4ff3eee77b41466d08117970970d01be6e48ffe1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import * as Cesium from 'cesium'
import { appointroutePlanning } from '@/api/RoutePlanning'
import { analyzeKmzFile, XMLToJSON } from '@/utils/cesium/kmz.js'
import { getLnglatAltitude } from '@/utils/cesium/mapUtil'
import cesiumOperation from '@/utils/cesium-tsa'
const { removeAllPoint, removeLeftClickEvent, flyTo } = cesiumOperation()
import {
  getCenterPoint,
  getLnglatDist,
  cartesian3Convert,
} from '@/utils/cesium/mapUtil.js'
export default {
  data () {
    return {
      //机场坐标信息
      droneCoordinates: null,
      switchSaving: false,
      clampToGroundshow: true,
    }
  },
  watch: {
    '$store.state.drone.selectedWorkSpaceId': {
      handler (wId) {
        this.switchSaving = true
        this.droneCoordinates = null
      },
      deep: true,
      immediate: true,
    },
    '$store.state.drone.deviceState': {
      handler (data) {
        if (this.switchSaving) return (this.switchSaving = false)
        if (this.droneCoordinates) return
        const deviceSn = data?.currentSn || ''
        const dockInfo = data?.dockInfo || ''
        const { longitude, latitude, height } =
          dockInfo[deviceSn]?.basic_osd || ''
        if (!longitude) return
        if (this.lastlongitude == longitude) return
        this.lastlongitude = longitude
        getLnglatAltitude(longitude, latitude, global.$viewer).then((res) => {
          this.droneCoordinates = Cesium.Cartesian3.fromDegrees(
            Number(longitude),
            Number(latitude),
            Number(res.height),
          )
        })
      },
      deep: true,
      immediate: true,
    },
    '$store.state.common.mapSetting.visual': {
      handler (mode) {
        removeLeftClickEvent()
        this.taskBoxis = false
        this.clampToGroundshow = mode === '2D' ? true : false
        if (!this.activeRow) return
        let tempRow = this.activeRow
        this.activeRow = null
        this.rowTriggerFn(tempRow)
      },
      deep: true,
      immediate: true,
    },
    //当选择航线规划数据时,任务列表不选中数据
    '$store.state.revokeTaskSelection': {
      handler (task) {
        removeAllPoint()
        this.activeRow = null
        this.taskBoxis = false
        if (!this.$refs.myTable) return
        this.$refs.myTable.setCurrentRow()
      },
      deep: true,
      immediate: false,
    },
  },
  methods: {
    // 判断是面状还是航线
    async judgeWaylineMode (route) {
      this.workspaceId = this.wId
      const { data: waylineUrl } = await appointroutePlanning(
        this.workspaceId,
        route.id,
      )
      if (waylineUrl.code !== 0)
        return this._showMessage.error(waylineUrl.message)
 
      const { fileInfoObj } = await analyzeKmzFile(
        `${waylineUrl.data}?_t=${new Date().getTime()}`,
      )
      const xmlStr = await fileInfoObj['wpmz/template.kml']
      const xmlJson = XMLToJSON(xmlStr)?.['Document']
      const placemark = xmlJson.Folder.Placemark
      if (placemark?.Polygon) {
        return 'planar'
      } else {
        return 'point'
      }
    },
    // 在机场和第一个点直接增加一个中间转折点
    addTurnPoint (firstPoint, SecondPoint) {
      const dronePosition = cartesian3Convert(firstPoint, global.$viewer)
      const firstPosition = cartesian3Convert(SecondPoint, global.$viewer)
      return new Cesium.Cartesian3.fromDegrees(
        dronePosition?.longitude,
        dronePosition?.latitude,
        firstPosition?.height,
      )
    },
    // 指向该区域
    flyToRouterShow (waylinePosition) {
      let cartesianlengthArr = waylinePosition.map((cartesian) => {
        return [
          cartesian3Convert(cartesian, global.$viewer).longitude,
          cartesian3Convert(cartesian, global.$viewer).latitude,
        ]
      })
      const centerpoint = getCenterPoint(cartesianlengthArr)
      let maxlength = 0
      cartesianlengthArr.forEach((item, index) => {
        let banseTwoPoints = getLnglatDist(
          item[0],
          item[1],
          centerpoint.lng,
          centerpoint.lat,
        )
        if (banseTwoPoints > maxlength) {
          maxlength = banseTwoPoints
        }
      })
      let flyNum = this.clampToGroundshow ? 7 : 12
      flyTo(
        { longitude: centerpoint.lng, latitude: centerpoint.lat },
        3,
        maxlength * flyNum,
      )
    },
  },
}