无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
import EventBus from '@/utils/eventBus'
import * as Cesium from 'cesium'
import { Cartesian3, Terrain, Viewer } from 'cesium'
import store from '@/store/index'
 
import getBaseConfig from '@/buildConfig/config'
 
const {
    imageryProvider_ammap,
    imageryProvider_ammapBz,
    imageryProvider_ammapSL,
    imageryProvider_stand,
    imageryProvider_standZh,
    imageryProvider_tdt_cia_w,
    imageryProvider_tdt_img_w,
 
    blueImageryProviderVec,
    blueImageryProviderCva,
} = getBaseConfig()
 
import { addBlueFilter } from '@/utils/cesium/common'
import { useBoundary } from '@/utils/cesium/useBoundary'
 
let smallMpaCenterDistance = null
let curCameraHpr = null
 
let proHandler = null
let proController = null
let proMoveFlag = null
 
let handler = null
/**
 * 公共的Cesium (蓝色,2d)
 */
 
// 封装的不用管
let cn = {
    ri: function () {
        return a
    },
 
    LS: function () {
        return o
    },
 
    jL: function () {
        return n
    },
}
function a (e) {
    return null != e
}
function o (e, t) {
    return a(e) ? e : t
}
 
function n (e, t = !1) {
    let { longitude: i, latitude: a, height: o } = e
    return Cesium.Cartesian3.fromDegrees(i, a, t ? 0 : o)
}
 
/**
 * 创建ztzf-cesium
 * @param {Object} options - 配置选项对象
 * @param {string} options.dom - Cesium 容器的 DOM 元素
 * @param {boolean} [options.flatMode=true] - 是否启用 2D 模式,默认为 true
 * @param {boolean} [options.terrain=false] - 是否启用地形,默认为 false
 * @param {number} [options.layerMode=17] - 图层模式,默认值为 17(蓝色底图)
 * @param {boolean} [options.contour=true] - 是否显示轮廓线,默认为 true
 * @param {boolean} [options.flyToContour=false] - 是否飞行到轮廓,默认为 false
 * @param {number} [options.multiple=1.4] - 范围倍数
 * @param {number} [options.dockOptions={}] - 机巢显示
 * @param {array} [options.boundaryChange] - 边界改变事件
 * @param {array} [options.boundaryColor] - 边界颜色
 * @param {array} [options.dockRangeType] - 机巢范围类型 1显示覆盖圆;2显示覆盖圈
 * @param {array} [options.useDockHeight] - 是否使用机巢高度,默认为false
 */
export class PublicCesium {
 
    constructor(options) {
        this.handlerLeftEvents = { handler: null }
        this.handlerRightEvents = { handler: null }
        this.handlerMouseMoveEvents = { handler: null }
        this.viewer = null
        this.globalBaseMapLayers = []
        this.boundary = null
        this.init(options)
    }
 
    init (options) {
        const {
            dom,
            flatMode = true,
            terrain = false,
            layerMode = 0,
            contour = true,
            // flyToContour = false,
            multiple = 1.4,
 
            dockOptions = {},
 
 
 
            dockRangeType = 1,
            useDockHeight = false
        } = options
        Cesium.Camera.DEFAULT_VIEW_FACTOR = -0.45
        // 西南东北,默认显示中国
        Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(66, 4, 135, 53.55)
        const viewerOptions = {
            infoBox: false, // 禁用沙箱,解决控制台报错
            animation: false, // 左下角的动画仪表盘
            baseLayerPicker: false, // 右上角的图层选择按钮
            geocoder: false, // 搜索框
            homeButton: false, // home按钮
            sceneModePicker: false, // 模式切换按钮
            timeline: false, // 底部的时间轴
            navigationHelpButton: false, // 右上角的帮助按钮,
            selectionIndicator: false, // 是否显示选择指示器
            baseLayer: false,
            fullscreenButton: false,
        }
 
        this.viewer = new Viewer(dom, viewerOptions)
        this.viewerDom = dom
 
        this.viewer.scene.globe.enableLighting = true
        this.viewer.shadows = false
        this.viewer.shadowMap.darkness = 0.5
 
        let time = new Date()
        time.setHours(12, 0, 0, 0)
        let utc = Cesium.JulianDate.fromDate(new Date(time))
 
        this.viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(utc, 0, new Cesium.JulianDate())
 
        // 边界,机巢
 
        this.viewer?.imageryLayers.removeAll()
        this.viewer._cesiumWidget._creditContainer.style.display = 'none'
        handler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 
        this.viewer?.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) // 禁用双击
 
        if (terrain) {
            try {
                Cesium.CesiumTerrainProvider.fromUrl(`${import.meta.env.VITE_APP_TERRAIN_URL}`, {
                    requestVertexNormals: true, // 启用地形法线增强立体感
                    requestWaterMask: true, // 启用水体遮罩效果
                }).then(terrainProvider => {
                    this.viewer.terrainProvider = terrainProvider
                })
            } catch (error) {
                console.error('地形加载失败:', error)
            }
        }
 
        this.viewer.scene.screenSpaceCameraController.maximumZoomDistance = 4500000
        this.switchLayers(layerMode)
        this.switchFlatMode(flatMode)
        // this.switchContour(contour)
        // flyToContour && this.flyToContour(contour)
    }
 
    getViewer () {
        return this.viewer
    }
 
    // 销毁viewer
    viewerDestroy (removeDom = true) {
        smallMpaCenterDistance = null
 
        if (this.viewer) {
            this.viewer?.entities.removeAll()
            this.viewer?.imageryLayers.removeAll()
            this.viewer?.dataSources.removeAll()
 
 
            // try {
            //     this.viewer?.scene?.primitives?.removeAll()
            //     this.viewer?.entities?.removeAll()
            // } catch (e) {
            //     console.warn('清理资源时出错:', e)
 
            //     console.log(this.viewer, 1111111111111)
            // }
 
            // 获取webgl上下文
            let gl = this.viewer?.scene.context._originalGLContext
            gl.canvas.width = 1
            gl.canvas.height = 1
            gl.getExtension("WEBGL_lose_context").loseContext()
            gl = null
            this.viewer?.destroy() // 销毁Viewer实例
            this.viewer = null
            var cesiumContainer = document.getElementById(this.viewerDom)
            if (cesiumContainer && removeDom) {
                cesiumContainer.remove() // 移除与地图相关的DOM元素
                this.viewerDom = null
            }
        }
    }
 
    setShowDock (sns) {
        // this.boundary?.setShowDock(sns)
    }
 
    // 切换轮廓显示
    // async switchContour (open) {
    //     if (open) {
    //         await this.boundary?.openContour()
    //     } else {
    //         this.boundary?.closeContour()
    //     }
    // }
    // // 飞向轮廓居中
    // flyToContour () {
    //     this.boundary?.flyToBoundary()
    // }
 
    // 飞行 flyto
    flyTo (pointOption, time = 4, height = 3000, orientation = {}, complete = () => { }) {
        if (!pointOption.longitude && !pointOption.latitude) return
        const destination = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude, height)
        const duration = time
        this.viewer?.camera.flyTo({
            destination,
            duration,
            orientation,
            complete,
        })
    }
 
    switchLayers (mode, roadLine = false) {
        let mapLayers = []
        this.globalBaseMapLayers?.forEach(item => {
            if (item.mapLayer) item.mapLayer.show = false
        })
        // store.state.common.mapSetting.mode = mode
        // 标准地图(天地图矢量)加载
        if (mode === 0) {
            mapLayers.push(
                ...[
                    { key: 'imageryProvider_standZh', layer: imageryProvider_standZh },
                    { key: 'imageryProvider_stand', layer: imageryProvider_stand },
                ]
            )
        }
        // 高德地图矢量图层加载
        if (mode === 2) {
            mapLayers.push({
                key: 'imageryProvider_ammapSL',
                layer: imageryProvider_ammapSL,
            })
        }
        // 高德影像地图数据图层
        if (mode === 3) {
            mapLayers.push(
                ...[
                    { key: 'imageryProvider_ammap', layer: imageryProvider_ammap },
                    { key: 'imageryProvider_ammapBz', layer: imageryProvider_ammapBz },
                ]
            )
        }
 
        // 天地图影像➕注记
        if (mode === 4) {
            mapLayers.push(
                ...[
                    { key: 'imageryProvider_standZh', layer: imageryProvider_standZh },
                    // { key: 'imageryProvider_tdt_cia_w', layer: imageryProvider_tdt_cia_w },
                    { key: 'imageryProvider_tdt_img_w', layer: imageryProvider_tdt_img_w },
                ]
            )
        }
 
        // 蓝色底图
        if (mode === 17) {
            mapLayers.push(
                ...[
                    { key: 'blueImageryProviderCva', layer: blueImageryProviderCva },
                    { key: 'blueImageryProviderVec', layer: blueImageryProviderVec },
                ]
            )
        }
 
        // 路线图加载
        if (roadLine === true && mode === 1) {
            mapLayers.push({ key: 'annotation', layer: imageryProvider_tdt_cia_w })
        }
 
        mapLayers.forEach(item => {
            let find = this.globalBaseMapLayers.find(item1 => item1.key === item.key)
            if (!find) {
                find = {
                    key: item.key,
                    mapLayer: this.viewer?.imageryLayers.addImageryProvider(item.layer),
                }
                this.globalBaseMapLayers.push(find)
            }
            find.mapLayer.show = true
            this.setCurrentLayerFilter(find, mode)
            this.viewer?.imageryLayers.lowerToBottom(find.mapLayer)
        })
    }
 
    // 设置或重置滤镜
 
    setCurrentLayerFilter (data, mode) {
        if (mode === 17) {
            data.mapLayer.brightness = 0.6 // 亮度(默认值)
            data.mapLayer.contrast = 1.8 // 对比度(负值降低对比度)
            data.mapLayer.hue = 1 // 色相(弧度值,3.0可能导致紫色)
            data.mapLayer.saturation = 0 // 增加饱和度强化蓝色
            data.mapLayer.gamma = 0.3 // 伽马校正(小于1.0使颜色更鲜艳)
 
            if (data.key === 'blueImageryProviderVec')
                addBlueFilter(
                    {
                        bInvertColor: true,
                        bFilterColor: true,
                        filterColor: '#4e70a6',
                    },
                    this.viewer,
                    true
                )
        } else {
            data.mapLayer.brightness = 1 // 亮度(默认值)
            data.mapLayer.contrast = 1 // 对比度(负值降低对比度)
            data.mapLayer.hue = 0 // 色相(弧度值,3.0可能导致紫色)
            data.mapLayer.saturation = 1 // 增加饱和度强化蓝色
            data.mapLayer.gamma = 1 // 伽马校正(小于1.0使颜色更鲜艳)
 
            addBlueFilter(
                {
                    bInvertColor: true,
                    bFilterColor: true,
                    filterColor: '#4e70a6',
                },
                this.viewer,
                false
            )
        }
    }
 
    // 切换为二三维模式 type:  true 2D  false 3D
    switchFlatMode (type) {
        if (type) {
            this.viewer?.scene.morphTo2D(0)
        } else {
            this.viewer?.scene.morphTo3D(0)
        }
    }
 
    // 右键点击事件
    addRightClickEvent (sid, cb, eventKey = 'rightHandler') {
        if (this.handlerRightEvents.rightHandler) this.removeRightClickEvent()
        if (this.handlerRightEvents[eventKey]) this.removeRightClickEvent(eventKey)
 
        this.handlerRightEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 
        this.handlerRightEvents[eventKey].setInputAction(click => {
            const pick = this.viewer?.scene.pick(click.position)
            cb(click, pick, this.viewer)
        }, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
    }
 
    // 移除鼠标右键事件
    removeRightClickEvent (eventKey = 'rightHandler') {
        if (!this.handlerRightEvents[eventKey]) return
        this.handlerRightEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)
 
        this.handlerRightEvents[eventKey] = null
    }
 
    addLeftDrillPickEvent (cb, eventKey = 'handler') {
        if (this.handlerLeftEvents.handler) this.removeLeftDrillPickEvent()
        if (this.handlerLeftEvents[eventKey]) this.removeLeftDrillPickEvent(eventKey)
 
        this.handlerLeftEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
        this.handlerLeftEvents[eventKey].setInputAction(click => {
            const picks = this.viewer?.scene.drillPick(click.position)
 
            cb(picks)
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
    }
 
    removeLeftDrillPickEvent (eventKey = 'handler') {
        if (this.handlerLeftEvents[eventKey] == null) return
        this.handlerLeftEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
 
        this.handlerLeftEvents[eventKey] = null
    }
 
    // 鼠标点击事件
    addLeftClickEvent (sid, cb, eventKey = 'handler') {
        if (this.handlerLeftEvents.handler) this.removeLeftClickEvent()
        if (this.handlerLeftEvents[eventKey]) this.removeLeftClickEvent(eventKey)
 
        this.handlerLeftEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
        this.handlerLeftEvents[eventKey].setInputAction(click => {
            const pick = this.viewer?.scene.pick(click.position)
 
            if (pick && pick.primitive && pick.primitive?.customParams?.type === '3DTileset') {
                return cb(click, pick, this.viewer, this.handlerLeftEvents[eventKey])
            }
 
            if (pick && pick.id && (pick.id._id === sid || pick.id._id.includes(sid))) {
                cb(click, pick, this.viewer, this.handlerLeftEvents[eventKey])
            }
 
            if (sid === null) {
                cb(click, pick, this.viewer, this.handlerLeftEvents[eventKey])
            }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
    }
 
    // 移除鼠标点击事件
    removeLeftClickEvent (eventKey = 'handler') {
        if (this.handlerLeftEvents[eventKey] == null) return
        this.handlerLeftEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
 
        this.handlerLeftEvents[eventKey] = null
    }
 
    // 鼠标移动事件
    addMouseHandler (sid, cb, eventKey = 'mouseHandler') {
        const that = this
        if (this.handlerMouseMoveEvents.mouseHandler) this.removeMouseHandler()
        if (this.handlerMouseMoveEvents[eventKey]) this.removeMouseHandler(eventKey)
 
 
        this.handlerMouseMoveEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 
        this.handlerMouseMoveEvents[eventKey].setInputAction(function (movement) {
            cb(movement, that.viewer)
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
    }
 
    // 移除鼠标移动事件
    removeMouseHandler (eventKey = 'mouseHandler') {
        if (this.handlerMouseMoveEvents[eventKey] == null) return
        this.handlerMouseMoveEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)
 
        this.handlerMouseMoveEvents[eventKey] = null
    }
 
    pointInitEvent (left_down, mouse_move, left_up) {
        if (this.pointEditHandler) this.pointUnInitEvent()
        this.pointEditHandler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
        const events = {
            left_down,
            mouse_move,
            left_up,
        }
 
        this.pointEditBindEvent(events)
        this.pointEditBindEvent(events, Cesium.KeyboardEventModifier.CTRL)
        this.pointEditBindEvent(events, Cesium.KeyboardEventModifier.ALT)
        this.pointEditBindEvent(events, Cesium.KeyboardEventModifier.SHIFT)
        this.pointEditBindEvent(events, Cesium.KeyboardEventModifier.META)
    }
 
    pointEditBindEvent (events, e) {
        if (this.pointEditHandler) {
            this.pointEditHandler.setInputAction(events.left_down(e), Cesium.ScreenSpaceEventType.LEFT_DOWN, e)
            this.pointEditHandler.setInputAction(events.mouse_move(e), Cesium.ScreenSpaceEventType.MOUSE_MOVE, e)
            this.pointEditHandler.setInputAction(events.left_up(e), Cesium.ScreenSpaceEventType.LEFT_UP, e)
        }
    }
 
    pointUnInitEvent () {
        this.pointEditUnBindEvent()
        this.pointEditUnBindEvent(Cesium.KeyboardEventModifier.CTRL)
        this.pointEditUnBindEvent(Cesium.KeyboardEventModifier.ALT)
        this.pointEditUnBindEvent(Cesium.KeyboardEventModifier.SHIFT)
        this.pointEditUnBindEvent(Cesium.KeyboardEventModifier.META)
 
        this.pointEditHandler = null
    }
 
    pointEditUnBindEvent (e) {
        this.pointEditHandler?.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOWN, e)
        this.pointEditHandler?.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE, e)
        this.pointEditHandler?.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_UP, e)
    }
 
    setCameraMove (e) {
        this.setCameraAttribute(e)
    }
 
    setCameraAttribute (e) {
        let t = {}
            , i = !1
 
        if (e.attitude) {
            let { fov: n } = e.attitude
 
            if ((0, cn.ri)(n) && this.viewer?.camera) {
                this.viewer.camera.frustum = new Cesium.PerspectiveFrustum({
                    fov: Cesium.Math.toRadians(n),
                    aspectRatio: this.viewer?.canvas.clientWidth / this.viewer?.canvas.clientHeight,
                    near: .1
                })
            }
        }
        i && this.viewer?.camera.setView(t)
    }
 
    setView (options) {
        const position = Cesium.Cartesian3.fromDegrees(
            Number(options.longitude),
            Number(options.latitude),
            Number(options.height || 0),
        )
        const heading = Number(options.heading || 0)
        this.viewer?.camera?.setView({
            destination: position,
            orientation: {
                heading: Cesium.Math.toRadians(heading >= 0 ? heading : heading + 360), // 水平旋转(偏航角)
                pitch: Cesium.Math.toRadians(Number(options.pitch || 0)),    // 俯仰角(-90°表示俯视地心)
                roll: 0.0                             // 翻转角
            }
        })
 
        this.getCameraCurPositionDistance()
    }
 
    getCameraCurPositionDistance () {
        if (!this.viewer) return
 
        // 获取相机位置
        const position = this.viewer?.camera.positionCartographic
        const cameraLongitude = Cesium.Math.toDegrees(position.longitude)
        const cameraLatitude = Cesium.Math.toDegrees(position.latitude)
        const cameraHeight = position.height
 
        // 获取地图区域中心点位置
        let mapCenterPx = {
            x: this.viewer?.canvas.clientWidth / 2,
            y: this.viewer?.canvas.clientHeight / 2
        }
 
        let centerInfo = this.getMouseInfo(mapCenterPx)
 
        if (centerInfo.wgs84SurfacePosition) {
            const {
                lng,
                lat,
                alt
            } = centerInfo.wgs84SurfacePosition
 
            // 计算相机到中心点的距离
            const cameraPosition = Cesium.Cartesian3.fromDegrees(cameraLongitude, cameraLatitude, cameraHeight)
            const centerPoint = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
            const distance = Cesium.Cartesian3.distance(cameraPosition, centerPoint)
 
            smallMpaCenterDistance = distance
            EventBus.emit('setCameraCurPositionDistance', distance)
        } else {
            const cameraPosition = this.viewer?.camera.position
            const farDistance = this.viewer?.camera.frustum.far // 获取相机的远裁剪面距离
            const distance = farDistance - Cesium.Cartesian3.magnitude(cameraPosition)
            smallMpaCenterDistance = distance
            EventBus.emit('setCameraCurPositionDistance', '')
        }
    }
 
    getMouseInfo (position) {
        let scene = this.viewer?.scene
        let surfaceCartesian = undefined
        let wgs84SurfacePosition = undefined
 
        if (
            scene.mode === Cesium.SceneMode.SCENE3D &&
            !(this.viewer?.terrainProvider instanceof Cesium.EllipsoidTerrainProvider)
        ) {
            let ray = scene.camera.getPickRay(position)
            surfaceCartesian = scene.globe.pick(ray, scene)
        } else {
            surfaceCartesian = scene.camera.pickEllipsoid(
                position,
                Cesium.Ellipsoid.WGS84,
            )
        }
 
        if (surfaceCartesian) {
            let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(surfaceCartesian)
            if (c) {
                wgs84SurfacePosition = {
                    lng: Cesium.Math.toDegrees(c.longitude),
                    lat: Cesium.Math.toDegrees(c.latitude),
                    alt: c.height,
                }
            }
        }
 
        return {
            wgs84SurfacePosition: wgs84SurfacePosition,
        }
    }
 
    getMouseInfoAll (position) {
        let scene = this.viewer?.scene
        let target = scene.pick(position)
        let cartesian = undefined
        let surfaceCartesian = undefined
        let wgs84Position = undefined
        let wgs84SurfacePosition = undefined
        if (scene.pickPositionSupported) {
            cartesian = scene.pickPosition(position)
        }
        if (cartesian) {
            let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian)
            if (c) {
                wgs84Position = {
                    lng: Cesium.Math.toDegrees(c.longitude),
                    lat: Cesium.Math.toDegrees(c.latitude),
                    alt: c.height,
                }
            }
        }
        if (
            scene.mode === Cesium.SceneMode.SCENE3D &&
            !(this.viewer?.terrainProvider instanceof Cesium.EllipsoidTerrainProvider)
        ) {
            let ray = scene.camera.getPickRay(position)
            surfaceCartesian = scene.globe.pick(ray, scene)
        } else {
            surfaceCartesian = scene.camera.pickEllipsoid(position, Cesium.Ellipsoid.WGS84)
        }
        if (surfaceCartesian) {
            let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(surfaceCartesian)
            if (c) {
                wgs84SurfacePosition = {
                    lng: Cesium.Math.toDegrees(c.longitude),
                    lat: Cesium.Math.toDegrees(c.latitude),
                    alt: c.height,
                }
            }
        }
 
        return {
            target: target,
            windowPosition: position,
            position: cartesian,
            wgs84Position: wgs84Position,
            surfacePosition: surfaceCartesian,
            wgs84SurfacePosition: wgs84SurfacePosition,
        }
    }
 
    // 左键按下事件
    pro_left_down (e) {
        proMoveFlag = !0
    }
 
    // 左键抬起事件
    pro_left_up (e) {
        proMoveFlag = !1
    }
 
    // 鹰眼鼠标移动事件
    pro_mouse_move (e) {
        if (proMoveFlag) {
            this.look3D(e.startPosition, e.endPosition)
 
            const position = this.viewer?.camera.positionCartographic
            const lng = Cesium.Math.toDegrees(position.longitude).toFixed(4)
            const lat = Cesium.Math.toDegrees(position.latitude).toFixed(4)
            const alt = (position.height / 1000).toFixed(2) // 转换为千米
 
            // 获取方向
            const heading = Cesium.Math.toDegrees(this.viewer?.camera.heading).toFixed(2)
            const pitch = Cesium.Math.toDegrees(this.viewer?.camera.pitch).toFixed(2)
            const roll = Cesium.Math.toDegrees(this.viewer?.camera.roll).toFixed(2)
 
            curCameraHpr = {
                heading,
                pitch,
                roll
            }
 
            let newHeading = ((heading + 180) % 360) - 180
            EventBus.emit('PointAirLine-setRoamPoint', {
                pitch: pitch,
                heading: newHeading >= 0 ? newHeading - 180 : newHeading + 180
            })
 
            this.getCameraCurPositionDistance()
        }
    }
 
    // 鹰眼地图相关事件
    bindEvent () {
        this.bindProLeftDown = this.pro_left_down.bind(this)
        this.bindProLeftUp = this.pro_left_up.bind(this)
        this.bindProLeftMove = this.pro_mouse_move.bind(this)
 
        proHandler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 
        proController = this.viewer?.scene.screenSpaceCameraController
 
        proController.enableRotate = !1
        proController.enableTilt = !1
        proController.enableZoom = !1
        proController.enableLook = !1
        proController.enableTranslate = !1
        proMoveFlag = false
 
        handler.setInputAction(this.bindProLeftDown, Cesium.ScreenSpaceEventType.LEFT_DOWN)
        handler.setInputAction(this.bindProLeftUp, Cesium.ScreenSpaceEventType.LEFT_UP)
        handler.setInputAction(this.bindProLeftMove, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
    }
 
    unBindEvent = () => {
        if (proHandler) {
            handler.removeInputAction(this.bindProLeftDown, Cesium.ScreenSpaceEventType.LEFT_DOWN)
            handler.removeInputAction(this.bindProLeftUp, Cesium.ScreenSpaceEventType.LEFT_UP)
            handler.removeInputAction(this.bindProLeftMove, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
 
            proController = null
            proHandler = null
        }
    }
 
    look3D (e, t, i = !1) {
        let r = this.viewer?.camera
            , a = this.viewer?.scene.globe.ellipsoid
            , s = i ? -1 : 2
            , o = a.geodeticSurfaceNormal(r.position)
        r.look(o, this.getLookAngle(e, t, "x") * s),
            this.lookVertical(-this.getLookAngle(e, t, "y") * s, o)
    }
 
    getLookAngle (e, t, i) {
        let r, a
        let s = e[i]
            , o = t[i]
            , n = new Cesium.Cartesian2("x" === i ? s : 0, "y" === i ? s : 0)
            , l = new Cesium.Cartesian2("x" === i ? o : 0, "y" === i ? o : 0)
            , c = this.viewer?.camera.getPickRay(n)
            , h = this.viewer?.camera.getPickRay(l)
        if (!c || !h)
            return 0
        this.viewer?.camera.frustum instanceof Cesium.OrthographicFrustum ? (r = c.origin,
            a = h.origin,
            Cesium.Cartesian3.add(this.viewer?.camera.direction, r, r),
            Cesium.Cartesian3.add(this.viewer?.camera.direction, a, a),
            Cesium.Cartesian3.subtract(r, this.viewer?.camera.position, r),
            Cesium.Cartesian3.subtract(a, this.viewer?.camera.position, a),
            Cesium.Cartesian3.normalize(r, r),
            Cesium.Cartesian3.normalize(a, a)) : (r = c.direction,
            a = h.direction)
        let d = Cesium.Cartesian3.dot(r, a)
            , p = 0
        return d < 1 && (p = Math.acos(d)),
            s > o ? -p : p
    }
 
    lookVertical (e, t) {
        let i = this.viewer?.camera
            , r = this.judgeParallelAndRecalculateAngle(-e, i.direction, t)
        r && i.look(i.right, r)
    }
 
    sg (e, t) {
        return Cesium.Cartesian3.equalsEpsilon(e, t, Cesium.Math.EPSILON2) ? 1 : Cesium.Cartesian3.equalsEpsilon(e, Cesium.Cartesian3.negate(t, new Cesium.Cartesian3), Cesium.Math.EPSILON2) ? -1 : 0
    }
 
    judgeParallelAndRecalculateAngle (e, t, i) {
        let r = this.sg(t, i)
            , a = e
        if (1 === r && a < 0)
            a = 0
        else if (-1 === r && a > 0)
            a = 0
        else if (0 === r) {
            let e = Cesium.Cartesian3.dot(t, i)
                , r = Cesium.Math.acosClamped(-e)
            a > 0 && a > r && (a = r - Cesium.Math.EPSILON4),
                r = Cesium.Math.acosClamped(e),
            a < 0 && -a > r && (a = -r + Cesium.Math.EPSILON4)
        }
        return a
    }
 
    getEntityById (id) {
        const pointEntity = this.viewer?.entities.getById(id)
        return pointEntity
    }
 
    removeById (id) {
        this.viewer?.entities.removeById(id)
        const pointEntity = this.viewer?.entities.getById(id)
        if (pointEntity && pointEntity !== undefined) {
            this.viewer?.entities.remove(pointEntity)
        }
    }
 
    removeAllPoint () {
        if (this.viewer) {
            this.viewer?.entities?.removeAll()
            // viewer?.scene?.primitives?.removeAll();
        }
    }
 
    // 添加entity
    addCustomImageryProviderDataSource (imageryLayers) {
        return this.viewer?.imageryLayers.addImageryProvider(imageryLayers)
    }
 
    showCustomImageryProviderDataSource (imageryLayers, show) {
        if (imageryLayers) {
            imageryLayers.show = show
        }
    }
 
 
    removeAllCustomImageryProviderDataSource (imageryLayers) {
        if (imageryLayers) {
            this.viewer?.imageryLayers.remove(imageryLayers)
        }
    }
}