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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
import * as Cesium from 'cesium'
import { appointroutePlanning } from '@/api/RoutePlanning'
import { analyzeKmzFile, XMLToJSON } from '@/utils/cesium/kmz.js'
import cesiumOperation from '@/utils/cesium-tsa'
import { getLnglatDist, cartesian3Convert } from '@/utils/cesium/mapUtil.js'
import ImageTrailMaterial from '@/utils/cesium/ImageTrailMaterial'
import { getLnglatAltitude, getPositionsHeight } from '@/utils/cesium/mapUtil'
 
import { PatchesgetInfoById } from '@/api/patternSpot'
 
const { getEntityById, removeById, addLeftClickEvent, removeLeftClickEvent } =
  cesiumOperation()
 
export default {
  inject: ["panelSwitchingElement"],
 
  data () {
    return {
      waylineDetails: [
        {
          label: '航线长度',
          value: 0,
        },
        {
          label: '预计执行时间',
          value: 0,
        },
        {
          label: '航点',
          value: 0,
        },
        {
          label: '照片',
          value: 0,
        },
      ],
      workspaceId: '',
      pointList: [],
      obtainWaypointData: [],
      nowObtainWaypointData: [],
      taskBoxis: false,
      pointEventList: [
        {
          label: '单拍',
          key: 'takePhoto',
          icon: require('@/assets/icons/waylinetool/camera.png'),
        },
        {
          label: '开始录像',
          key: 'startRecord',
          icon: require('@/assets/icons/waylinetool/camera-on.png'),
        },
        {
          label: '结束录像',
          key: 'stopRecord',
          icon: require('@/assets/icons/waylinetool/camera-off.png'),
        },
        {
          label: '变焦',
          key: 'zoom',
          icon: require('@/assets/icons/waylinetool/holdertilt.png'),
        },
        {
          label: '创建新文件夹',
          key: 'customDirName',
          icon: require('@/assets/icons/waylinetool/create-file.png'),
        },
        {
          label: '旋转云台',
          key: 'gimbalRotate',
          icon: require('@/assets/icons/waylinetool/holderyaw.png'),
        },
        {
          label: '飞行器偏航',
          key: 'rotateYaw',
          icon: require('@/assets/icons/waylinetool/droneyaw.png'),
        },
        {
          label: '悬停等待',
          key: 'hover',
          icon: require('@/assets/icons/waylinetool/xt.png'),
        },
        {
          label: '航段间均匀转动云台pitch角',
          key: 'gimbalEvenlyRotate',
        },
        {
          label: '精准复拍动作',
          key: 'accurateShoot',
        },
        {
          label: '精准复拍动作',
          key: 'orientedShoot',
        },
        {
          label: '全景拍照动作',
          key: 'panoShot',
          icon: require('@/assets/icons/waylinetool/panoramicview.png'),
        },
        {
          label: '点云录制操作',
          key: 'recordPointCloud',
        },
      ],
      dockPosition: [],
      //机场坐标信息
      droneCoordinates: null,
      lastlongitude: null,
      spotData: [],
 
    }
  },
 
  methods: {
    // 读取kmz文件
    async initPointWayline (route) {
      if (!route) return
      this.workspaceId =
        localStorage.getItem('bs_workspace_id') ||
        this.$store.state.drone.selectedWorkSpaceId
      const { data: waylineUrl } = await appointroutePlanning(
        this.workspaceId,
        this.wayline?.id || 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']
      this.pointList = xmlJson.Folder.Placemark
      if (!getEntityById(route.id)) {
        this.drawWayline(xmlJson, route)
      }
      if (
        !route.patches_id ||
        route.patches_id == 'null' ||
        route.patches_id == ''
      )
        return
      this.obtainSpotInfo(xmlJson)
      this.spottedSurfaceGet(route)
    },
    // 绘制航线到地图上
    async drawWayline (xmlJson, route) {
      const points = xmlJson?.['Folder']?.['Placemark']
      //每个点数据
      let waylinePosition = []
      this.obtainWaypointData = []
      let SpecialPointsd = false
 
      getPositionsHeight(points, global.$viewer).then((res) => {
        waylinePosition = res.map((item) => {
          return Cesium.Cartesian3.fromDegrees(
            Number(item.longitude),
            Number(item.latitude),
            item.FinalHeight,
          )
        })
 
        res.forEach((item, index) => {
          let setting = {}
 
          if (index === 0) {
            let firstPoint = cartesian3Convert(
              waylinePosition[index],
              global.$viewer,
            )
            let dornePoint = cartesian3Convert(
              this.droneCoordinates,
              global.$viewer,
            )
            let getLongOk = getLnglatDist(
              firstPoint.longitude,
              firstPoint.latitude,
              dornePoint.longitude,
              dornePoint.latitude,
            )
            if (getLongOk < 20) {
              setting = {
                id: 'route_point_' + index,
                position: waylinePosition[index],
                billboard: {
                  image: require('@/assets/images/Startingpointicon.png'),
                  pixelOffset: new Cesium.Cartesian2(0, -13),
                  outlineWidth: 0,
                  width: 30,
                  height: 30,
                  scale: 1.0,
                },
              }
            } else {
              setting = {
                id: 'route_point_' + index,
                position: waylinePosition[index],
                billboard: {
                  image: this.createBillboard(`${index + 1}`, '#FFBA00FF'),
                  pixelOffset: new Cesium.Cartesian2(0, -13),
                  outlineWidth: 0,
                },
              }
              SpecialPointsd = true
            }
          } else if (index === points.length - 1) {
            setting = {
              id: 'route_point_' + index,
              position: waylinePosition[index],
              billboard: {
                image: require('@/assets/images/EndPointicon.png'),
                pixelOffset: new Cesium.Cartesian2(0, -13),
                outlineWidth: 0,
                width: 30,
                height: 30,
                scale: 1.0,
              },
            }
          } else {
            setting = {
              id: 'route_point_' + index,
              position: waylinePosition[index],
              billboard: {
                image: this.createBillboard(
                  `${SpecialPointsd ? index + 1 : index}`,
                  '#FFBA00FF',
                ),
                pixelOffset: new Cesium.Cartesian2(0, -13),
                outlineWidth: 0,
              },
            }
          }
 
          global.$viewer.entities.add(setting)
          this.addClickevents('route_point_' + index, waylinePosition[index])
          if (item?.['actionGroup']) {
            this.obtainWaypointInfo(item?.['actionGroup']?.['action'], index)
          }
        })
 
        waylinePosition.unshift(this.droneCoordinates)
        //没有起点坐标时,在机场和第一个点增加一个中间转折点作为起点
        if (SpecialPointsd) {
          let cartesian = this.addTurnPoint(
            waylinePosition[0],
            waylinePosition[1],
          )
          waylinePosition.splice(1, 0, cartesian)
          if (getEntityById('route_detailSpecialPointsd')) {
            removeById('route_detailSpecialPointsd')
          }
          global.$viewer.entities.add({
            position: cartesian,
            id: 'route_detailSpecialPointsd',
            billboard: {
              image: require('@/assets/images/Startingpointicon.png'),
              width: 30,
              height: 30,
              pixelOffset: new Cesium.Cartesian2(0, -20),
            },
          })
        }
        global.$viewer.entities.add({
          id: 'route_wayline_line',
          polyline: {
            positions: waylinePosition,
            width: 5,
            material: new ImageTrailMaterial({
              color: Cesium.Color.WHITE,
              speed: 10,
              image: require('@/assets/images/arrow-right-blue.png'),
              repeat: { x: waylinePosition.length, y: 0 },
            }),
            zIndex: 1,
            clampToGround: this.clampToGroundshow,
          },
        })
        this.$store.commit('SET_WAYLINE_POINTS', {
          type: 'point',
          data: waylinePosition,
        })
        this.flyToRouterShow(waylinePosition)
      })
    },
    // 在机场和第一个点直接增加一个中间转折点
    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,
      )
    },
    // 增加鼠标监听事件,点击展示事件
    addClickevents (tragetPointint_id, currentPositionxyz) {
      addLeftClickEvent(tragetPointint_id, startPointEvent)
      const _this = this
      //鼠标点击展示详情
      function startPointEvent (click, pick, viewer) {
        // 当前点击项获取数据
        let id = pick?.id?._id.split('_')[2]
        let getNowData = _this.obtainWaypointData.find(
          (obj) => obj.subIndex == id,
        )
        if (getNowData) {
          _this.nowObtainWaypointData = getNowData.label
        }
        // 展示详情
        _this.taskBoxis = true
        viewer.container.appendChild(_this.$refs.taskBox)
        viewer.scene.postRender.addEventListener(() => {
          let windowCoord = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
            global.$viewer.scene,
            currentPositionxyz,
          )
          if (!_this.$refs.taskBox) return
          const x = windowCoord.x + 25
          const y = windowCoord.y - _this.$refs.taskBox.offsetHeight / 2 - 15
          _this.$refs.taskBox.style.transform = `translate3d(${Math.round(
            x,
          )}px,${Math.round(y)}px,${Math.round(40)}px )`
        })
      }
    },
    // 创建广告牌
    createBillboard (title, color) {
      const billboard = document.createElement('canvas')
      const ctx = billboard.getContext('2d')
      ctx.beginPath()
      ctx.ellipse(150, 90, 11, 11, 0, 0, Math.PI * 2)
      ctx.fillStyle = color
      ctx.fill()
      ctx.font = 'bold 15px serif'
      ctx.textAlign = 'center'
      ctx.fillStyle = '#ffffff'
      ctx.fillText(title, 150, 95)
      ctx.closePath()
      return billboard
    },
    // 添加图斑面
    spottedSurfaceGet (wayline) {
      this.spotData = wayline.patches_id.split(',')
      this.spotData.forEach((item, index) => {
        PatchesgetInfoById({ patchesId: item }).then((polygonRes) => {
          if (polygonRes.data.data === '') return
          const dkfw = polygonRes.data.data.dkfw
          const numbersWithCommas = dkfw.match(/\d+(\.\d+)?/g)
          const grouped = numbersWithCommas.map((item) => Number(item))
          if (getEntityById('task_polygon_dk_wayline' + index)) {
            removeById('task_polygon_dk_wayline' + index)
          }
          global.$viewer.entities.add({
            id: 'task_polygon_dk_wayline' + index,
            polyline: {
              positions: Cesium.Cartesian3.fromDegreesArray(grouped),
              width: 1,
              material: Cesium.Color.RED,
              zIndex: 0,
              clampToGround: true,
            },
          })
        })
      })
    },
    // 所有点事件
    obtainWaypointInfo (obtainlist, index) {
      if (Array.isArray(obtainlist)) {
        let eventData = []
        obtainlist.forEach((item) => {
          let eventName = item?.['actionActuatorFunc']?.['#text']
          eventData.push(this.findValueByLabel(eventName))
        })
        this.obtainWaypointData.push({
          label: eventData,
          subIndex: index,
        })
      } else {
        let eventName = obtainlist?.['actionActuatorFunc']?.['#text']
        this.obtainWaypointData.push({
          label: [this.findValueByLabel(eventName)],
          subIndex: index,
        })
      }
    },
    // 获取图斑块与拍摄的图片信息
    obtainSpotInfo (xmlJson) {
      let mergedArray = []
      this.panelSwitchingElement.updateObtainSpotData([])
 
      const points = xmlJson?.['Folder']?.['Placemark'].slice(1)
      for (let [i, entity] of points.entries()) {
        if (entity?.['actionGroup']) {
          // 点位信息
          let PointPosition =
            entity?.['Point']?.['coordinates']?.['#text'].split(',')
          // 当前所在图斑
          let takePhotoName = ''
          //  只有一个事件
          if (!entity?.['actionGroup']?.['action'].length) {
            let takePhotoHas =
              entity?.['actionGroup']?.['action']?.['actionActuatorFunc']?.[
              '#text'
              ]
            if (takePhotoHas === 'takePhoto') {
              takePhotoName = this.getSpotName(
                entity?.['actionGroup']?.['action'],
              )
              const takePhotoData = {
                PointPosition: [
                  Number(PointPosition[0]),
                  Number(PointPosition[1]),
                ],
                takePhotoName: takePhotoName,
              }
              mergedArray.push(takePhotoData)
            }
          }
          // 存在多个事件
          else {
            entity?.['actionGroup']?.['action'].forEach((item, index) => {
              if (item?.['actionActuatorFunc']?.['#text'] === 'takePhoto') {
                takePhotoName = this.getSpotName(item)
                const takePhotoData = {
                  PointPosition: [
                    Number(PointPosition[0]),
                    Number(PointPosition[1]),
                  ],
                  takePhotoName: takePhotoName,
                }
                mergedArray.push(takePhotoData)
              }
            })
          }
        }
      }
 
      this.panelSwitchingElement.updateObtainSpotData(Array.from(
        mergedArray
          .reduce((map, obj) => {
            let takePhotoName = obj.takePhotoName
            if (!map.has(takePhotoName)) {
              map.set(takePhotoName, [])
            }
            map.get(takePhotoName).push(obj)
            return map
          }, new Map())
          .values(),
      ))
    },
    // 获取图斑名称
    getSpotName (str) {
      let strIn = str?.['actionActuatorFuncParam']?.['fileSuffix']?.['#text']
      let startIndex = strIn.indexOf('航点') + '航点'.length
      let endIndex = strIn.indexOf('~')
      return strIn.substring(startIndex, endIndex)
    },
 
    // 根据key获取label
    findValueByLabel (keyToFind) {
      return this.pointEventList.find((obj) => obj.key === keyToFind)
    },
    // 取消详细信息展示
    cancleTaskBoxis () {
      this.taskBoxis = false
      this.nowObtainWaypointData = []
    },
  },
  mounted () { },
  destroyed () {
    removeLeftClickEvent()
    let taskBox = document.getElementById('taskBox')
    if (!taskBox) return
    taskBox.remove()
  },
}