liuyg
2021-06-29 f656f66c0b2dfa0e52b25f41c761f03b5997262b
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
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-openAnalysis',
            name: 'openAnalysis',
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginopenAnalysis", lang.hitch(this, this.beginopenAnalysis));
                topic.subscribe("closesopenAnalysis", lang.hitch(this, this.closesopenAnalysis));
                // topic.publish('getbeginSlope', that.beginSlope);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesopenAnalysis();
                })
 
 
                // that.beginopenAnalysis();
 
            },
            beginopenAnalysis: function () {
                console.log(Cesium.ViewDome, 111)//缺少Cesium.ViewDome支持
                console.log(`${this.name}--kaishi`);
                var that = this;
 
                var viewer = that.map;
                var scene = viewer.scene;
                var widget = viewer.cesiumWidget;
                var longitude, latitude, height;
                var viewDomeArray = []; //存多个开敞度对象数组
                var ViewDomeType = 0; //开敞度类型
                var isClosed = false; //是否封口
                var handler;
                var iTime, Time; //定时器
                var URL_CONFIG = window.MYURL_CONFIG;
 
                viewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({
                    key: URL_CONFIG.BING_MAP_KEY,//可至官网(https://www.bingmapsportal.com/)申请key
                    url: URL_CONFIG.BINGMAP
                }));
                var promise = scene.open(URL_CONFIG.SCENE_CBD);
                Cesium.when(promise, function (layers) {
                    for (var i = 0; i < layers.length; i++) {
                        layers[i].selectEnabled = false;
                    }
                    //图层加载完成,设置相机位置
                    scene.camera.setView({
                        destination: Cesium.Cartesian3.fromDegrees(116.4491, 39.9011, 180),
                        orientation: {
                            heading: 0.0912,
                            pitch: -0.3177,
                            roll: 0
                        }
                    });
                    $("#activeopenAnalysis").on("click", function () {
                        mousestyle();
                        initViewDome();
                        // handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
                        // console.log(handler, 31313131313)
                        // handler.setInputAction(function (e) {
                        //     viewer.enableCursorStyle = true;
                        //     $('body').removeClass('drawCurshizi');
                        //     //获取点击位置笛卡尔坐标
                        //     var position = scene.pickPosition(e.position);
                        //     //将笛卡尔坐标转化为经纬度坐标
                        //     let positions = [];
                        //     var cartographic = Cesium.Cartographic.fromCartesian(position);
                        //     longitude = Cesium.Math.toDegrees(cartographic.longitude);
                        //     latitude = Cesium.Math.toDegrees(cartographic.latitude);
                        //     height = cartographic.height;
                        //     if (height < 0) {
                        //         height = 0;
                        //     }
                        //     if (positions.indexOf(longitude) == -1 && positions.indexOf(latitude) == -1) {
                        //         positions.push(longitude);
                        //         positions.push(latitude);
                        //         positions.push(height);
                        //     }
                        //     //点击位置同步到显示框
                        //     $("#longitudeopenAnalysis").val(longitude);
                        //     $("#latitudeopenAnalysis").val(latitude);
                        //     $("#heightopenAnalysis").val(height);
                        //     updateViewDome(positions);
                        //     handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
                        // }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
                    })
 
                    function initViewDome() {  //初始化
                        console.log(1121)
                        // let VisibleColor = Cesium.Color.fromCssColorString($("#VisibleColoropenAnalysis").val());
                        // let HiddenColor = Cesium.Color.fromCssColorString($("#HiddenColoropenAnalysis").val());
                        // let viewDome = new Cesium.ViewDome(scene); //构造新的开敞度分析对象
                        // viewDome.viewPosition = [longitude, latitude, height]; //视点位置,这里用的是CBD示例的中心位置
                        // viewDome.distance = Number($("#observerRsdiusopenAnalysis").val());//可视距离
                        // viewDome.domeType = ViewDomeType; //开敞度类型,分为可视部分、不可视部分, 全部显示
                        // viewDome.visibleAreaColor = Cesium.Color.fromAlpha(VisibleColor, 0.5); //可视部颜色
                        // viewDome.hiddenAreaColor = Cesium.Color.fromAlpha(HiddenColor, 0.5); //隐藏部分颜色
                        // viewDome.startAngle = Number($("#StartingAngleopenAnalysis").val());//起始角度
                        // viewDome.endAngle = Number($("#EndAngleopenAnalysis").val());//终止角度
                        // viewDome.isClosed = isClosed;  //封口
                        // viewDome.build(); //执行开敞度分析
                        // viewDomeArray.push(viewDome)
                        console.log(Cesium.ViewDome, 111)//缺少Cesium.ViewDome
                        console.log(1131)
                    }
 
                    function move() {   //改变经纬度动态移动
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        if (longitude && latitude && height) {
                            viewDomeArray[viewDomeArray.length - 1].viewPosition = [longitude, latitude, height];
                        }
                        clearTimeout(Time); //防止点击多次,执行一次
                        Time = setTimeout(function () {
                            viewDomeArray[viewDomeArray.length - 1].startAngle = Number($("#StartingAngleopenAnalysis").val()) //加这个才起作用
                        }, 500);
                    }
 
                    function updateViewDome(p) {
                        viewDomeArray[viewDomeArray.length - 1].viewPosition = p;
                        viewDomeArray[viewDomeArray.length - 1].build(); //执行开敞度分析
                        addpoint()
                    }
 
                    function mousestyle() { //鼠标样式
                        viewer.enableCursorStyle = false;
                        viewer._element.style.cursor = '';
                        $('body').removeClass('drawCurshizi').addClass('drawCurshizi');
                    }
 
                    //结果清除
                    function clear() {
                        viewer.entities.removeAll();
                        viewDomeArray[viewDomeArray.length - 1].destroy();//释放对象
                        viewDomeArray.pop();
                        if (viewDomeArray.length == 0) {
                            return
                        } else {
                            let v = viewDomeArray[viewDomeArray.length - 1];
                            $("#longitudeopenAnalysis").val(v.viewPosition[0]);
                            $("#latitudeopenAnalysis").val(v.viewPosition[1]);
                            $("#heightopenAnalysis").val(v.viewPosition[2]);
                            longitude = v.viewPosition[0];
                            latitude = v.viewPosition[1];
                            height = v.viewPosition[2];
                            addpoint()
                        }
                    }
 
                    function addpoint() {//添加点
                        if (longitude == undefined || latitude == undefined || height == undefined) {
                            return
                        }
                        //首先移除之前添加的点
                        viewer.entities.removeAll();
                        //在位置添加对应点
                        viewer.entities.add(new Cesium.Entity({
                            point: new Cesium.PointGraphics({
                                color: new Cesium.Color(1, 0, 0),
                                pixelSize: 6,
                                outlineColor: new Cesium.Color(0, 1, 1)
                            }),
                            position: Cesium.Cartesian3.fromDegrees(longitude, latitude, height + 0.5)
                        }));
 
                    }
 
                    $('#clearopenAnalysis').click(function () {
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        clear();
                        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
                    });
                    $("#longitudeopenAnalysis").bind("input propertychange", function () {
                        longitude = parseFloat($("#longitudeopenAnalysis").val());
                        if (!longitude) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            move()
                        }, 1000);
                        addpoint()
                    })
                    $("#latitudeopenAnalysis").bind("input propertychange", function () {
                        latitude = parseFloat($("#latitudeopenAnalysis").val());
                        if (!latitude) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            move()
                        }, 1000);
                        addpoint()
                    })
                    $("#heightopenAnalysis").bind("input propertychange", function () {
                        height = parseFloat($("#heightopenAnalysis").val());
                        if (!height) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            move()
                        }, 1000);
                        addpoint()
                    })
                    $('#observerRsdiusopenAnalysis').bind('input propertychange', function () {
                        $("#RsdiusopenAnalysis").val($("#observerRsdiusopenAnalysis").val());
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        if (Number($("#observerRsdiusopenAnalysis").val()) == 0) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            viewDomeArray[viewDomeArray.length - 1].distance = Number($("#observerRsdiusopenAnalysis").val())
                        }, 500);
                    });
                    $('#RsdiusopenAnalysis').bind('input propertychange', function () {
                        $("#observerRsdiusopenAnalysis").val($("#RsdiusopenAnalysis").val())
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        if (Number($("#observerRsdiusopenAnalysis").val()) == 0) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            viewDomeArray[viewDomeArray.length - 1].distance = Number($("#observerRsdiusopenAnalysis").val())
                        }, 500);
                    });
 
                    $('#StartingAngleopenAnalysis').bind('input propertychange', function () {
                        $("#SangleopenAnalysis").val($("#StartingAngleopenAnalysis").val());
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            viewDomeArray[viewDomeArray.length - 1].startAngle = Number($("#StartingAngleopenAnalysis").val())
                        }, 500);
                    });
                    $('#SangleopenAnalysis').bind('input propertychange', function () {
                        $("#StartingAngleopenAnalysis").val($("#SangleopenAnalysis").val());
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            viewDomeArray[viewDomeArray.length - 1].startAngle = Number($("#StartingAngleopenAnalysis").val())
                        }, 500);
                    });
 
                    $('#EndAngleopenAnalysis').bind('input propertychange', function () {
                        $("#EangleopenAnalysis").val($("#EndAngleopenAnalysis").val());
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            viewDomeArray[viewDomeArray.length - 1].endAngle = Number($("#EndAngleopenAnalysis").val())
                        }, 500);
                    });
                    $('#EangleopenAnalysis').bind('input propertychange', function () {
                        $("#EndAngleopenAnalysis").val($("#EangleopenAnalysis").val());
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        clearTimeout(iTime);
                        iTime = setTimeout(function () {
                            viewDomeArray[viewDomeArray.length - 1].endAngle = Number($("#EndAngleopenAnalysis").val())
                        }, 500);
                    });
 
                    $("#VisibleColoropenAnalysis").bind("input propertychange", function () {
                        let VisibleColor = Cesium.Color.fromCssColorString($("#VisibleColoropenAnalysis").val())
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        viewDomeArray[viewDomeArray.length - 1].visibleAreaColor = Cesium.Color.fromAlpha(VisibleColor, 0.5); //可视部颜色
                    })
                    $("#HiddenColoropenAnalysis").bind("input propertychange", function () {
                        let HiddenColor = Cesium.Color.fromCssColorString($("#HiddenColoropenAnalysis").val())
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        viewDomeArray[viewDomeArray.length - 1].hiddenAreaColor = Cesium.Color.fromAlpha(HiddenColor, 0.5);
                    })
 
                    $("#calMode1openAnalysis").on("input change", function () {
                        var index = document.getElementById("calMode1openAnalysis").selectedIndex;
                        switch (index) {
                            case 0:
                                ViewDomeType = Cesium.ViewDomeType.VISIBLEDOME;
                                break;
                            case 1:
                                ViewDomeType = Cesium.ViewDomeType.HIDDENDOME;
                                break;
                            case 2:
                                ViewDomeType = Cesium.ViewDomeType.ALLDOME;
                                break;
                            default:
                                break;
                        }
                        if (viewDomeArray.length == 0) {
                            return
                        }
                        viewDomeArray[viewDomeArray.length - 1].domeType = ViewDomeType
                    });
 
                    $("#isClosedopenAnalysis").click(function () {
                        if ($(this).prop("checked")) {
                            isClosed = true
                        } else {
                            isClosed = false
                        }
                        viewDomeArray[viewDomeArray.length - 1].isClosed = isClosed;
                    });
 
                    $('#toolbaropenAnalysis').show();
                    $('#loadingbaropenAnalysis').remove();
 
                }, function (e) {
                    if (widget._showRenderLoopErrors) {
                        var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                        widget.showErrorPanel(title, undefined, e);
                    }
                })
 
                //关闭操作框
                $(".close2").click(function () {
                    $("#toolbaropenAnalysis").hide();
                    $("#bnopenAnalysis").show()
                });
                $("#bnopenAnalysis").click(function () {
                    $("#toolbaropenAnalysis").show();
                    $("#bnopenAnalysis").hide()
                });
 
            },
            closesopenAnalysis: function (froms) {
                console.log(`${this.name}--guanbi`);
                var that = this;
            },
            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);
            }
 
        });
    });