liuyg
2021-06-25 f26fde54fdc51424030eed8e9a0fc4c6529f1ac2
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
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-volumeAnalysis',
            name: 'volumeAnalysis',
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginVolumeAnalysis", lang.hitch(this, this.beginVolumeAnalysis));
                topic.subscribe("closesVolumeAnalysis", lang.hitch(this, this.closesVolumeAnalysis));
                // topic.publish('getbeginSlope', that.beginSlope);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesVolumeAnalysis();
                })
 
                // that.beginVolumeAnalysis();
 
            },
            beginVolumeAnalysis: function () {
                // console.log('kaishi');
                var that = this
                    , viewer = this.map;
 
                var clampMode = 0; // 空间模式
                var scene = viewer.scene;
                var widget = viewer.cesiumWidget;
 
                var tooltip = window.MYcreateTooltip(document.body);
 
                // var promise = scene.open('http://www.supermapol.com/realspace/services/3D-dxyx_ios2/rest/realspace')
                // Cesium.when.all(promise, function (layers) {//等待promise加载
                    //设置相机位置、视角
                    // viewer.scene.camera.setView({
                    //     destination: new Cesium.Cartesian3(-1206939.1925299785, 5337998.241228442, 3286279.2424502545),
                    //     orientation: {
                    //         heading: 1.4059101895600987,
                    //         pitch: -0.20917672793046682,
                    //         roll: 2.708944180085382e-13
                    //     }
                    // });
 
                    var handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, clampMode);
 
                    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 (handlerPolygon.isDrawing) {
                            tooltip.showAt(windowPosition, '<p>点击确定多边形中间点</p><p>右键单击结束绘制</p>');
                        } else {
                            tooltip.showAt(windowPosition, '<p>点击绘制第一个点</p>');
                        }
                    });
 
                    handlerPolygon.drawEvt.addEventListener(function (result) {
                        handlerPolygon.polygon.show = false;
                        // handlerPolygon.polyline.show = false;
                        handlerPolygon.deactivate();
                        tooltip.setVisible(false);
 
                        var dep = document.getElementById("depthVolumeAnalysis").value;
 
                        var array = [].concat(result.object.positions);
                        var positions = [];
                        var positionsii = [];
                        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(parseInt(dep));
 
                                positionsii.push({
                                    x: longitude,
                                    y: latitude
                                });
                            }
                        }
 
                        //此处用的地形修改 而不是地形开挖
                        viewer.scene.globe.removeAllModifyRegion();
                        viewer.scene.globe.addModifyRegion({
                            name: 'ggg',
                            position: positions
                        });
 
                        var length = [];
                        length.push(positionsii.length);
 
                        //需要在此 动态构造一个 REGION类型的对象
                        var geometry = {
                            "id": 23,
                            "parts": length,
                            "points": positionsii,
                            "style": null,
                            "type": "REGION"
                        };
 
 
                        var queryObj = {
                            "cutFillType": "REGIONANDALTITUDE",
                            "baseAltitude": dep,
                            "region": geometry,
                            "resultDataset": "result",
                            "buildPyramid": true,
                            "deleteExistResultDataset": true
                        };
                        var queryObjJSON = JSON.stringify(queryObj);
                        $.ajax({
                            type: 'post',
                            url: "http://www.supermapol.com/realspace/services/spatialAnalysis-dxyx_ios/restjsr/spatialanalyst/datasets/DEM@%E5%9B%9B%E5%A7%91%E5%A8%98%E5%B1%B1/terraincalculation/cutfill.json?returnContent=true",
                            data: queryObjJSON,
                            success: function (data) {
                                console.log(data);
                                console.log(queryObj);
                                // var resultObj = JSON.parse(data);
                                var resultObj = data;
 
                                document.getElementById("cutareaVolumeAnalysis").value = resultObj.cutArea;
                                document.getElementById("cutVolumeVolumeAnalysis").value = resultObj.cutVolume;
                                document.getElementById("fillareaVolumeAnalysis").value = resultObj.fillArea;
                                document.getElementById("fillVolumeVolumeAnalysis").value = resultObj.fillVolume;
                                document.getElementById("remainderAreaVolumeAnalysis").value = resultObj.remainderArea;
                            }
                        });
 
                    });
 
                    document.getElementById("filladdVolumeAnalysis").onclick = function () {
                        handlerPolygon.activate();
                    };
 
                    document.getElementById("fillclearVolumeAnalysis").onclick = function () {
                        viewer.scene.globe.removeAllModifyRegion();
                        document.getElementById("cutareaVolumeAnalysis").value = "";
                        document.getElementById("cutVolumeVolumeAnalysis").value = "";
                        document.getElementById("fillareaVolumeAnalysis").value = "";
                        document.getElementById("fillVolumeVolumeAnalysis").value = "";
                        document.getElementById("remainderAreaVolumeAnalysis").value = "";
                        handlerPolygon.clear();
                    };
 
                    $('#toolbarVolumeAnalysis').show();
                    $('#loadingbar').remove();
 
 
                    if (!scene.pickPositionSupported) {
                        alert('不支持深度拾取,无法进行鼠标交互绘制!');
                    }
                // })
                that.handlerPolygon = handlerPolygon;
                that.tooltip = tooltip;
 
            },
            handlerPolygon: '',
            tooltip: '',
            closesVolumeAnalysis: function (froms) {
                // console.log('guanbi');
                this.map.scene.globe.removeAllModifyRegion();
                document.getElementById("cutareaVolumeAnalysis").value = "";
                document.getElementById("cutVolumeVolumeAnalysis").value = "";
                document.getElementById("fillareaVolumeAnalysis").value = "";
                document.getElementById("fillVolumeVolumeAnalysis").value = "";
                document.getElementById("remainderAreaVolumeAnalysis").value = "";
                this.handlerPolygon.clear();
                this.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);
            }
 
        });
    });