shuishen
2021-06-25 0b0ba7a298364d60567d1c2fbe30c2f2a9000def
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
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-throughSee',
            name: 'throughSee',
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginthroughSee", lang.hitch(this, this.beginthroughSee));
                topic.subscribe("closesthroughSee", lang.hitch(this, this.closesthroughSee));
                // topic.publish('getbeginSlope', that.beginSlope);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesthroughSee();
                })
 
 
                // that.beginthroughSee();
 
            },
            beginthroughSee: function () {
                console.log(`${this.name}--kaishi`);
                var that = this;
 
                var viewer = that.map;
 
                if (!viewer.scene.pickPositionSupported) {
                    alert('不支持深度纹理,通视分析功能无法使用(无法添加观测点目标点)!');
                }
                $("#toolbarthroughSee").show();
                $('#loadingbar').remove();
                var scene = viewer.scene;
                scene.shadowMap.darkness = 1.275; //设置第二重烘焙纹理的效果(明暗程度)
                scene.skyAtmosphere.brightnessShift = 0.4;  //修改大气的亮度
                scene.debugShowFramesPerSecond = false;
                scene.hdrEnabled = false;
                scene.sun.show = false;
                // 01设置环境光的强度-新处理CBD场景
                scene.lightSource.ambientLightColor = new Cesium.Color(0.65, 0.65, 0.65, 1);
                // 添加光源
                var position1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 480);
                //光源方向点
 
                var targetPosition1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 430);
                var dirLightOptions = {
                    targetPosition: targetPosition1,
                    color: new Cesium.Color(1.0, 1.0, 1.0, 1),
                    intensity: 0.55
                };
                directionalLight_1 = new Cesium.DirectionalLight(position1, dirLightOptions);
                scene.addLightSource(directionalLight_1);
                var sightline = new Cesium.Sightline(scene);
 
                var widget = viewer.cesiumWidget;
                // try {
 
                // var promise = scene.open(window.MYURL_CONFIG.SCENE_CBD);
                // Cesium.when.all(promise, function (layer) {
                // scene.camera.setView({
                //     destination: new Cesium.Cartesian3.fromDegrees(116.44621857300415, 39.899281526734555, 216.7793905027196),
                //     orientation: {
                //         heading: 0.41348036210986194,
                //         pitch: -0.13636490404291735,
                //         roll: 6.283185307179563
                //     }
                // });
                // for (var i = 0; i < layer.length; i++) {
                //     layer[i].selectEnabled = false;
                // }
 
                sightline.build();
                // }, function (e) {
                //     if (widget._showRenderLoopErrors) {
                //         var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                //         widget.showErrorPanel(title, undefined, e);
                //     }
                // });
                // } catch (e) {
                //     if (widget._showRenderLoopErrors) {
                //         var title = '渲染时发生错误,已停止渲染。';
                //         widget.showErrorPanel(title, undefined, e);
                //     }
                // }
 
 
                var addViewFlag = false;//当前点击状态是否是 添加观察点
                var addTargetFlag = false;//当前点击状态是否是 添加目标点
                var mv = false;//当前点击状态是否是 添加观察点
                var tf = false;//当前点击状态是否是 添加目标点
 
                var num = 0;//添加的目标点的点号
                that.couldRemove = false;//是否能移除目标点
                that.tooltip = window.MYcreateTooltip(viewer._element)
                var handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
                handlerPoint.drawEvt.addEventListener(function (result) {
                    //添加观察点
                    if (addViewFlag) {
                        var point = result.object;
                        // point.show = false;
                        var position = result.object.position;
 
                        //将获取的点的位置转化成经纬度
                        var cartographic = Cartesian2toDegrees(position);
 
                        //设置观察点
                        sightline.viewPosition = cartographic;
                        addViewFlag = false;
                    }
                    handlerPoint.deactivate();
                });
 
 
 
 
                that.handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
 
                document.getElementById("addViewPointthroughSee").onclick = function () {
                    if (tf == false) {
                        addViewFlag = true;
 
                        if (handlerPoint.active) {
                            return;
                        }
                        viewer.entities.removeAll();
                        if (that.couldRemove) {
                            sightline.removeAllTargetPoint();
                        }
                        handlerPoint.activate();
                        that.handler.setInputAction(function (evt) {
 
                            //鼠标移动,更新最后一次添加的目标点的位置
                            var position = scene.pickPosition(evt.endPosition);
 
                        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
 
                        if (addViewFlag || addTargetFlag) {
                            viewer.enableCursorStyle = false;
                            viewer._element.style.cursor = '';
                            $('body').removeClass('drawCur').addClass('drawCur');
                        }
                        //鼠标移动事件,更新点
                        that.handler.setInputAction(function (evt) {
                            that.tooltip.showAt(evt.endPosition, '<p>点击确定观察点</p>');
                        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        //鼠标点击事件,添加点
                        that.handler.setInputAction(function (e) {
                            $('body').removeClass('drawCur');
                            mv = true;
                            that.tooltip.setVisible(false);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
                    } else {
                        layer.tips('正在添加目标点,请先右键关闭', $('#addViewPointthroughSee'), { tips: [1, 'red'] });
                    }
                }
 
 
                document.getElementById("addTargetPointthroughSee").onclick = function () {
                    if (mv) {
                        addViewFlag = false;
                        addTargetFlag = true;
                        tf = true;
                        if (addViewFlag || addTargetFlag) {
                            viewer.enableCursorStyle = false;
                            viewer._element.style.cursor = '';
                            $('body').removeClass('drawCur').addClass('drawCur');
                        }
 
                        //鼠标点击事件,添加点
                        that.handler.setInputAction(function (e) {
                            var position = scene.pickPosition(e.position);
                            addTarget(position);
                        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
 
                        //鼠标移动事件,更新点
                        that.handler.setInputAction(function (evt) {
 
                            //鼠标移动,更新最后一次添加的目标点的位置
                            var position = scene.pickPosition(evt.endPosition);
 
                            if (num > 0) {
                                sightline.removeTargetPoint("point0");
 
                                var cartographic = Cartesian2toDegrees(position);
 
                                var flag = sightline.addTargetPoint({
                                    position: cartographic,
                                    name: "point0"
                                });
                            }
                            that.tooltip.showAt(evt.endPosition, '<p>点击确定目标点右键结束</p>');
                        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
 
                        //鼠标右键事件,结束
                        that.handler.setInputAction(function () {
                            viewer.enableCursorStyle = true;
                            $('body').removeClass('drawCur');
                            that.tooltip.setVisible(false);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                            that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                            tf = false;
                        }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
                    } else {
                        layer.tips('未添加观察点', $('#addTargetPointthroughSee'), { tips: [1, 'red'] });
                    }
                };
 
                document.getElementById("clearthroughSee").onclick = function () {
                    if (tf == false) {
                        addViewFlag = false;
                        addTargetFlag = false;
                        mv = false;
                        tf = false;
                        handlerPoint.clear();
                        that.tooltip.setVisible(false);
                        viewer.entities.removeAll();
                        that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        if (that.couldRemove) {
                            sightline.removeAllTargetPoint();
                            that.couldRemove = false;
                        }
                        viewer.enableCursorStyle = true;
                        $('body').removeClass('drawCur');
                    } else {
                        layer.tips('正在添加目标点,请先右键关闭', $('#clearthroughSee'), { tips: [1, 'red'] });
 
                    }
                }
 
 
 
 
                //添加通视点
                function addTarget(CartesianPosition) {
                    if (addViewFlag === false && addTargetFlag) {
                        num += 1;
                        //将获取的点的位置转化成经纬度
                        var cartographic = Cartesian2toDegrees(CartesianPosition);
                        //添加目标点
                        var name = "point" + num;
                        var flag = sightline.addTargetPoint({
                            position: cartographic,
                            name: name
                        });
                        that.couldRemove = true;
                    }
                }
 
                //笛卡尔转换为经纬度
                function Cartesian2toDegrees(position) {
                    var cartographic = Cesium.Cartographic.fromCartesian(position);
                    var longitude = Cesium.Math.toDegrees(cartographic.longitude);
                    var latitude = Cesium.Math.toDegrees(cartographic.latitude);
                    var height = cartographic.height;
 
                    return [longitude, latitude, height];
                }
 
                // that.promise = promise;
                that.addViewFlag = addViewFlag;
                that.addTargetFlag = addTargetFlag;
                that.handlerPoint = handlerPoint;
                that.sightline = sightline;
 
            },
            // promise: '',
            addViewFlag: '',
            addTargetFlag: '',
            couldRemove: '',
            sightline: '',
            tooltip: '',
            handler: '',
            handlerPoint: '',
            closesthroughSee: function (froms) {
                console.log(`${this.name}--guanbi`);
                that = this;
 
                // Cesium.when.all(that.promise, function (layer) {
                //     for (var i = 0; i < layer.length; i++) {
                //         that.map.scene.layers.remove(layer[i].name)
                //     }
                // })
                if (that.handler.removeInputAction) {
                    that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                    that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                }
                if (that.tooltip.setVisible) {
                    that.tooltip.setVisible(false);
                }
                if (that.handlerPoint.clear) {
                    that.handlerPoint.clear();
                }
                that.addViewFlag = false;
                that.addTargetFlag = false;
 
                that.map.entities.removeAll();
                if (that.couldRemove) {
                    that.sightline.removeAllTargetPoint();
                    that.couldRemove = false;
                }
                that.map.enableCursorStyle = true;
                $('body').removeClass('drawCur');
            },
            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);
            }
 
        });
    });