liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
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();
                })
 
                $("#beginigTheEarth").click(() => {
                    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
                //     }
                // });
 
                var tooltip = window.MYcreateTooltip(viewer._element);
                // console.log(viewer._element, 534)
                //绘制多边形
                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) {
                    // console.log(windowPosition,534)
                    // console.log(handlerPolygon.isDrawing,555)
                    // console.log(viewer._element, 534)
                    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;
 
                    that.closesDigTheEarth();
                };
 
                if (!scene.pickPositionSupported) {
                    alert('不支持深度纹理,无法绘制多边形,地形开挖功能无法使用!');
                }
                $('#toolbardigTheEarth').show();
                $('#loadingbar').remove();
                that.handlerPolygon = handlerPolygon;
                that.tooltip = tooltip;
            },
            handlerPolygon: '',
            tooltip: '',
            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;
                }
                if (that.handlerPolygon.deactivate) {
                    that.handlerPolygon.deactivate();
                }
                if(that.tooltip.setVisible){
                    that.tooltip.setVisible(false);
                }
            },
            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);
            }
 
        });
    });