liuyg
2021-06-22 c3bb18b5acb4c8453c6f86a376dd37bd93ae3bc3
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
define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/_base/array',
    'dojo/_base/html',
    'dojo/topic',
    'jimu/BaseWidget',
],
    function (declare,
        lang,
        array,
        html,
        topic,
        BaseWidget
    ) {
        return declare([BaseWidget], {
            baseClass: 'jimu-widget-digTheEarth',
            name: 'digTheEarth',
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginDigTheEarth", lang.hitch(this, this.beginDigTheEarth));
                topic.subscribe("closesDigTheEarth", lang.hitch(this, this.closesDigTheEarth));
                // topic.publish('getbeginSlope', that.beginSlope);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesDigTheEarth();
                })
 
                // that.beginDigTheEarth();
            },
            beginDigTheEarth: function () {
                var that = this
                    , viewer = that.map;
                // console.log('kaishi');
 
                // viewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({
                //     url: 'https://dev.virtualearth.net',
                //     mapStyle: Cesium.BingMapsStyle.AERIAL,
                //     key: 'AkOyUpgDCoz063AWW1WfHnxp5222UBdxLOp1XvRv0tuebQnr2S7UcZkiLgME7gX0'
                // }));
                var scene = viewer.scene;
                // 设置相机视角
                // viewer.scene.camera.setView({
                //     destination: Cesium.Cartesian3.fromDegrees(88.3648, 29.0946, 90000),
                //     orientation: {
                //         heading: 6.10547067016156,
                //         pitch: -0.8475077031996778,
                //         roll: 6.2831853016686185
                //     }
                // });
                function createTooltip(frameDiv) {//抄录createTooltip函数
 
                    var tooltip = function (frameDiv) {
 
                        var div = document.createElement('DIV');
                        div.className = "twipsy right";
 
                        var arrow = document.createElement('DIV');
                        arrow.className = "twipsy-arrow";
                        div.appendChild(arrow);
 
                        var title = document.createElement('DIV');
                        title.className = "twipsy-inner";
                        div.appendChild(title);
 
                        this._div = div;
                        this._title = title;
                        this.message = '';
 
                        // add to frame div and display coordinates
                        frameDiv.appendChild(div);
                        var that = this;
                        div.onmousemove = function (evt) {
                            that.showAt({ x: evt.clientX, y: evt.clientY }, that.message);
                        };
                    };
 
                    tooltip.prototype.setVisible = function (visible) {
                        this._div.style.display = visible ? 'block' : 'none';
                    };
 
                    tooltip.prototype.showAt = function (position, message) {
                        if (position && message) {
                            this.setVisible(true);
                            this._title.innerHTML = message;
                            this._div.style.left = position.x + 10 + "px";
                            this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
                            this.message = message;
                        }
                    };
 
                    return new tooltip(frameDiv);
                }
                var tooltip = createTooltip(viewer._element);
                //绘制多边形
                var handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, 0);
                handlerPolygon.activeEvt.addEventListener(function (isActive) {
                    if (isActive == true) {
                        viewer.enableCursorStyle = false;
                        viewer._element.style.cursor = '';
                        $('body').removeClass('drawCur').addClass('drawCur');
                    }
                    else {
                        viewer.enableCursorStyle = true;
                        $('body').removeClass('drawCur');
                    }
                });
                handlerPolygon.movingEvt.addEventListener(function (windowPosition) {
                    if (windowPosition.x < 200 && windowPosition.y < 150) {
                        tooltip.setVisible(false);
                        return;
                    }
                    if (handlerPolygon.isDrawing) {
                        tooltip.showAt(windowPosition, '<p>点击确定开挖区域中间点</p><p>右键单击结束绘制,进行开挖</p>');
                    }
                    else {
                        tooltip.showAt(windowPosition, '<p>点击绘制开挖区域第一个点</p>');
                    }
                });
                handlerPolygon.drawEvt.addEventListener(function (result) {
                    if (!result.object.positions) {
                        tooltip.showAt(result, '<p>请绘制正确的多边形</p>');
                        handlerPolygon.polygon.show = false;
                        handlerPolygon.polyline.show = false;
                        handlerPolygon.deactivate();
                        handlerPolygon.activate();
                        return;
                    };
                    var array = [].concat(result.object.positions);
                    tooltip.setVisible(false);
                    var positions = [];
                    for (var i = 0, len = array.length; i < len; i++) {
                        var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
                        var longitude = Cesium.Math.toDegrees(cartographic.longitude);
                        var latitude = Cesium.Math.toDegrees(cartographic.latitude);
                        var h = cartographic.height;
                        if (positions.indexOf(longitude) == -1 && positions.indexOf(latitude) == -1) {
                            positions.push(longitude);
                            positions.push(latitude);
                            positions.push(h);
                        }
                    }
                    var dep = $('#depth').val();
                    viewer.scene.globe.removeAllExcavationRegion();
                    viewer.scene.globe.addExcavationRegion({
                        name: 'ggg',
                        position: positions,
                        height: dep,
                        transparent: false
                    });
                    handlerPolygon.polygon.show = false;
                    handlerPolygon.polyline.show = false;
                    handlerPolygon.deactivate();
                    handlerPolygon.activate();
                });
                handlerPolygon.activate();
                document.getElementById("cleardigTheEarth").onclick = function () {
                    viewer.scene.globe.removeAllExcavationRegion();
                    if (handlerPolygon.polygon) {
                        handlerPolygon.polygon.show = false;
                    }
                    if (handlerPolygon.polyline) {
                        handlerPolygon.polyline.show = false;
                    }
                    // handlerPolygon.polygon.show = false;
                    // handlerPolygon.polyline.show = false;
                };
 
                if (!scene.pickPositionSupported) {
                    alert('不支持深度纹理,无法绘制多边形,地形开挖功能无法使用!');
                }
                $('#toolbardigTheEarth').show();
                $('#loadingbar').remove();
                that.handlerPolygon = handlerPolygon;
            },
            handlerPolygon: '',
            closesDigTheEarth: function () {
                // console.log('gaunbi');
                var that = this;
                that.map.scene.globe.removeAllExcavationRegion();
                if (that.handlerPolygon.polygon) {
                    that.handlerPolygon.polygon.show = false;
                }
                if (that.handlerPolygon.polyline) {
                    that.handlerPolygon.polyline.show = false;
                }
                that.handlerPolygon.deactivate();
 
            },
            onOpen: function () {
 
            },
 
            onClose: function () {
                //面板关闭的时候触发 (when this panel is closed trigger)
                console.log('jies')
            },
 
            onMinimize: function () {
                this.resize();
            },
 
            onMaximize: function () {
                this.resize();
            },
 
            resize: function () {
 
            },
 
            destroy: function () {
                //销毁的时候触发
                //todo
                //do something before this func
                this.inherited(arguments);
            }
 
        });
    });