shuishen
2022-04-29 4f55f7d94198eca8eba9ae6b85af19a07cac2f79
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
/*
 * @Descripttion:
 * @version: 0.01
 * @Author: Morpheus
 * @Date: 2020-10-22 11:05:09
 * @LastEditors: Morpheus
 * @LastEditTime: 2020-10-22 13:48:22
 */
 
import store from '@/store/index'
class DivForms {
    /**
     * @popup 存放 dom 相关
     *
     */
    constructor(viewer, popup) {
        this._viewer = viewer
        this._popup = popup
        this._position = popup.position
        this.appendPopup()
    }
 
    get viewer () {
        return this._viewer
    }
 
    get popup () {
        return this._popup
    }
 
    get position () {
        return this._position
    }
 
    appendPopup () {
        /**
         * @domId 存放 dom 的id, 多个数组,单个字符串
         */
 
        this.createVideoWindowAll(this._popup.domId)
    }
 
    // 创建元素并追加
    createVideoWindowAll (id) {
        this.clearMove(id)
 
        this._viewer.scene.postRender.addEventListener(this.movePopup(id))
    }
 
    movePopup (id) {
        var self = this
        return function () {
            var position = global.DC.Transform.transformCartesianToWGS84(self._position[0])
            var positionChange = null
            if (store.state.viewer.twoOrThree == '三 维') {
                positionChange = global.DC.Transform.transformWGS84ToCartesian(
                    new global.DC.Position(
                        Number(position.lng),
                        Number(position.lat),
                        Number(0)
                    )
                )
            } else {
                positionChange = global.DC.Transform.transformWGS84ToCartesian(
                    new global.DC.Position(
                        Number(position.lng),
                        Number(position.lat),
                        Number(150)
                    )
                )
            }
 
            const windowCoord = global.DC.Namespace.Cesium.SceneTransforms.wgs84ToWindowCoordinates(
                self._viewer.scene,
                positionChange
            )
 
            self.positionPopUp(windowCoord, id)
        }
    }
 
    clearMove (id) {
        this._viewer.scene.postRender.removeEventListener(this.movePopup(id))
    }
 
    positionPopUp (windowCoord, id) {
        if (document.getElementById(id) == null || document.getElementById(id) == undefined) {
            this._viewer.scene.postRender.removeEventListener(this.movePopup(id))
            return
        }
        if (windowCoord != undefined && windowCoord.x && windowCoord.x != undefined && !Number.isNaN(windowCoord.x) &&
            windowCoord.y && windowCoord.y != undefined && !Number.isNaN(windowCoord.y)) {
            const x = windowCoord.x
            const y = windowCoord.y - document.getElementById(id).offsetHeight
            // x = windowCoord.x - document.getElementById(id).offsetWidth
 
            document.getElementById(id).style.cssText = `
            visibility:visible;
            transform:translate3d(${Math.round(x)}px,${Math.round(y)}px, 0);
            `
        }
    }
}
 
export default DivForms