赣州市洪水风险预警系统三维版本
guoshilong
2023-02-27 4d8c6dd77427e8e581fda17b6b65ba86bfb7a815
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
///////////////////////////////////////////////////////////////////////////
// Copyright © 2019 zhongsong. All Rights Reserved.
// 模块描述:监测预警
///////////////////////////////////////////////////////////////////////////
define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', 'dojo/_base/html', 'dojo/topic', 'jimu/BaseWidget', 'libs/laydate/laydate.js', 'libs/layer/layer.js'], function (declare, lang, array, html, topic, BaseWidget, laydate, layer) {
    return declare([BaseWidget], {
        baseClass: 'jimu-widget-ComprehensiveSupervise',
        name: 'ComprehensiveSupervise',
        ind: null,
        surveillanceEntityId: [],
        surveillanceEntityData: [],
        infor: null,
        cartesian: null,
        handler: null,
 
        startup: function startup() {
            // this.inherited(arguments);
            var that = this;
            var scene = that.map.scene;
            // 保存左侧菜单栏的点击下标
            var cont = $('.jimu-widget-ComprehensiveSupervise .supervise-content');
            $('.jimu-widget-ComprehensiveSupervise .supervise-meau ul li').click(function () {
                if ($(this).index() == that.ind) return;
                $(this).addClass('on').siblings().removeClass('on');
                // 监测
                if (!$('.jimu-widget-Hydrology').is(':hidden')) {
                    topic.publish("closehydrology", 'Hydrology');
                }
                // 预警
                if (!$('.jimu-widget-RiskEarlyWarning').is(':hidden')) {
                    topic.publish("closeRiskEarlyWarning", 'RiskEarlyWarning');
                }
                // 视频
                if (!$('.video').is(':hidden')) {
                    $('.video').stop().hide();
                    that.removeSuperEntity();
                    if (that.infor) {
                        $('#superTrackPopup').stop().hide();
                        that.cartesian = null;
                    }
                }
                // 值班
                if (!$('.supervise-patrol-duty').is(':hidden')) {
                    $('.supervise-patrol-duty').stop().hide();
                }
 
                if ($(this).index() == 1) {
                    cont.append($('.jimu-widget-Hydrology').stop().show());
                    $('.jimu-widget-Hydrology .hydro-list-mean a:eq(0)').trigger('click');
                } else if ($(this).index() == 0) {
                    cont.append($('.jimu-widget-RiskEarlyWarning').stop().show());
                    topic.publish("openRiskEarlyWarning", 'RiskEarlyWarning');
                } else if ($(this).index() == 2) {
                    $('.supervise-content .video-list ul').empty();
                    $.ajax({
                        url: './widgets/ComprehensiveSupervise/data.json',
                        type: 'get',
                        dataType: 'json',
                        success: function success(data) {
                            // 将data的值赋值给全局变量
                            data.data.forEach(function (item, index) {
                                $('.supervise-content .video-list ul').append($('<li>\n\t\t\t\t\t\t\t\t\t\t\t<img src=\'' + item.localurl + '\' alt=\'' + item.name + '\' title=\'' + item.name + '\' lng=\'' + item.longitude + '\' httpurl=\'' + item.monitor + '\' ltt=\'' + item.latitude + '\'> \n\t\t\t\t\t\t\t\t\t\t\t<span>' + item.name + '</span> \n\t\t\t\t\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t\t\t\t\t\t<i>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<img src="./images/video-playback.png" alt="">\n\t\t\t\t\t\t\t\t\t\t\t\t</i>\n\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t</li>'));
                                if (item.longitude != "" && item.latitude != "") {
                                    that.map.entities.add({
                                        id: 'super' + item.localurl,
                                        name: item.name,
                                        position: Cesium.Cartesian3.fromDegrees(Number(item.longitude), Number(item.latitude)),
                                        billboard: {
                                            image: './images/surveillance-entity.png', // img 与实体相关的图片
                                            show: true,
                                            width: 26,
                                            height: 26,
                                            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                                        }
                                    });
                                    that.surveillanceEntityId.push('super' + item.localurl);
                                    that.surveillanceEntityData.push(item);
                                }
                            });
                            that.onClickEntitys();
                        }
                    });
                    $('.video').stop().show();
                } else if ($(this).index() == 3) {
                    that.onclickTime();
                    $('.supervise-patrol-duty').stop().show();
                }
                that.ind = $(this).index();
            });
 
            $('.video ul').on('click', 'li', function () {
 
                if ($(this).children('img').attr('lng') == "" && $(this).children('img').attr('ltt') == "") {
                    that.openLayerSuper($(this).children('span').attr('sitename'), $(this).children('img').attr('httpurl'));
                    return;
                }
                if (that.infor) {
                    $('#superTrackPopup').remove('');
                }
                that.map.camera.flyTo({
                    destination: Cesium.Cartesian3.fromDegrees(Number($(this).children('img').attr('lng')), Number($(this).children('img').attr('ltt')), 10000),
                    easingFunction: Cesium.EasingFunction.QUADRACTIC_IN_OUT
                });
                that.cartesian = Cesium.Cartesian3.fromDegrees(Number($(this).children('img').attr('lng')), Number($(this).children('img').attr('ltt')), 200);
 
                var firstPosition = Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, that.cartesian);
                that.infor = that.createTrackPopup($(this).children('img').attr('httpurl'), $(this).children('span').text());
                $('.jimu-widget-ComprehensiveSupervise').append(that.infor);
                $('#superTrackPopupContent').css({
                    "top": firstPosition.x - $("#superTrackPopupContent")[0].offsetWidth / 2 + 'px',
                    "left": firstPosition.y - ($("#superTrackPopupContent")[0].offsetHeight + 20) + 'px'
                });
                that.map.scene.postRender.addEventListener(function () {
                    if (that.cartesian) {
                        that.updataPopup(that.cartesian);
                    }
                });
            });
 
            $('#link_tips').mouseover(function () {
                $('.jimu-widget-ComprehensiveSupervise .link-enlarge-address').stop().show();
            });
 
            $('#link_tips').mouseout(function () {
                $('.jimu-widget-ComprehensiveSupervise .link-enlarge-address').stop().hide();
            });
 
            // 监控放大
            $('.jimu-widget-ComprehensiveSupervise').on('click', '#superTrackPopupContent img', function () {
                that.openLayerSuper($(this).attr('sitename'), $(this).attr('src'));
            });
 
            $('.jimu-widget-ComprehensiveSupervise').on('click', '#superTrackPopupContent .superTrackClose', function () {
                if (that.infor) {
                    $('#superTrackPopup').stop().hide();
                    that.cartesian = null;
                }
            });
 
            // 日期查询事件
            // $('.supervise-patrol-duty date input:eq(1)').click(function () {
            //     var date = $(this).prev().val();
            // })
        },
        // 窗体移动
        updataPopup: function updataPopup(cartesian) {
            if (!cartesian) return;
            console.log(cartesian);
            var px_position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(this.map.scene, cartesian);
            var trackPopUpContent = window.document.getElementById("superTrackPopupContent");
            var popw = document.getElementById("superTrackPopupContent").offsetWidth;
            var poph = document.getElementById("superTrackPopupContent").offsetHeight;
            trackPopUpContent.style.left = px_position.x - popw / 2 + "px";
            trackPopUpContent.style.top = px_position.y - (poph + 20) + "px";
        },
        // 创建窗体
        createTrackPopup: function createTrackPopup(src, name) {
            var tarckpopup = $('<div id=\'superTrackPopup\'>\n\t\t\t\t\t\t\t\t\t<div id=\'superTrackPopupContent\'>\n\t\t\t\t\t\t\t\t\t\t<i\tclass=\'superTrackClose\'>\n\t\t\t\t\t\t\t\t\t\t\t\xD7\n\t\t\t\t\t\t\t\t\t\t</i>\n\t\t\t\t\t\t\t\t\t\t<img src=\'' + src + '\' sitename=\'' + name + '\'>\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t<i class="superTrackBtm">\n\t\t\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t\t</i>\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</div>');
            return tarckpopup;
        },
        // 打开layer弹框
        openLayerSuper: function openLayerSuper(name, url) {
            var wid = $(window).width() + 'px';
            var hei = $(window).height() + 'px';
            layer.open({
                title: name,
                type: 1,
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: [wid, hei],
                content: '<img src=\'' + url + '\' width=\'100%\' height=\'100%\' style=\'vertical-align: middle;\'>',
                id: "ComprehensiveSupervise",
                closeBtn: 1,
                success: function success(layero, index) {}
            });
        },
        // 删除实体
        removeSuperEntity: function removeSuperEntity() {
            var _this = this;
 
            if (this.surveillanceEntityId.length > 0) {
                this.surveillanceEntityId.forEach(function (item, index) {
                    _this.map.entities.removeById(item);
                });
                this.surveillanceEntityId = [];
            }
        },
        // 点击实体
        onClickEntitys: function onClickEntitys() {
            var that = this;
            that.handler = new Cesium.ScreenSpaceEventHandler(that.map.scene.canvas);
 
            that.handler.setInputAction(function (movement) {
                that.cartesian = null;
                if (that.infor) {
                    $('#superTrackPopup').stop().hide();
                }
                var pick = that.map.scene.pick(movement.position);
                var ray = that.map.camera.getPickRay(movement.position);
                cartesian = that.cartesian;
 
                if (pick && pick.id) {
                    if (that.surveillanceEntityId.indexOf(pick.id.id) != -1) {
                        // that.cartesian = that.map.scene.globe.pick(ray, that.map.scene);
                        var cartographic = Cesium.Cartographic.fromCartesian(pick.id.position._value);
                        var lat = Cesium.Math.toDegrees(cartographic.latitude);
                        var lng = Cesium.Math.toDegrees(cartographic.longitude);
                        that.cartesian = Cesium.Cartesian3.fromDegrees(Number(lng), Number(lat), 200);
                        if (that.infor) {
                            $('#superTrackPopup').remove('');
                        }
                        that.infor = that.createTrackPopup(that.surveillanceEntityData[that.surveillanceEntityId.indexOf(pick.id.id)].monitor, that.surveillanceEntityData[that.surveillanceEntityId.indexOf(pick.id.id)].name);
 
                        $('.jimu-widget-ComprehensiveSupervise').append(that.infor);
 
                        that.map.scene.postRender.addEventListener(function () {
                            if (that.cartesian) {
                                that.updataPopup(that.cartesian);
                            }
                        });
                    } else {
                        $('#superTrackPopup').stop().hide();
                    }
                }
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
        },
 
        onOpen: function onOpen() {
            //切换地球底层颜色
            this.map.scene.globe.baseColor = Cesium.Color.WHITE;
            //切换底图影像
            $($('div.cesium-viewer').find('.cesium-baseLayerPicker-choices')[0]).children('div:eq(0)').trigger('click');
 
            this.ind = null;
            this.surveillanceEntityId = [];
            this.surveillanceEntityData = [];
            this.infor = null;
            this.cartesian = null;
            this.handler = null;
            //面板打开的时候触发 (when open this panel trigger)
            $('.jimu-widget-ComprehensiveSupervise .supervise-meau ul li:eq(0)').trigger('click');
 
            laydate.render({
                elem: '#supervisePatrolDutyData', //指定元素
                type: "date",
                format: 'yyyy-MM-dd HH:mm',
                btns: ['confirm'],
                trigger: 'click',
                done: function done(value) {
                    $($(this)[0].elem[0]).val(value);
                }
            });
        },
 
        onClose: function onClose() {
            //面板关闭的时候触发 (when this panel is closed trigger)
            topic.publish("closehydrology", 'Hydrology');
            topic.publish("closeRiskEarlyWarning", 'RiskEarlyWarning');
            this.removeSuperEntity();
            if ($('#superTrackPopup')) $('#superTrackPopup').remove('');
            if (this.handler) this.handler.destroy();
            this.cartesian = null;
        },
 
        onMinimize: function onMinimize() {
            this.resize();
        },
 
        onMaximize: function onMaximize() {
            this.resize();
        },
 
        resize: function resize() {},
 
        destroy: function destroy() {
            //销毁的时候触发
            //todo
            //do something before this func
            this.inherited(arguments);
        },
 
        onclickTime: function onclickTime() {
 
            // 当前时间
            var timestamp = Date.parse(new Date());
 
            var serverDate = new Date(timestamp);
            //本周周日的的时间
 
 
            // 年
            var currentYear = serverDate.getFullYear();
 
            //月
 
            var currentMonth = serverDate.getMonth() + 1 < 10 ? '0' + (serverDate.getMonth() + 1) : serverDate.getMonth() + 1;
 
            //日
 
            var currentDay = serverDate.getDate() < 10 ? '0' + serverDate.getDate() : serverDate.getDate();
 
            $('#supervisePatrolDutyData').val(currentYear + '-' + currentMonth + '-' + currentDay + ' 00:00');
 
            console.log(currentYear + '-' + currentMonth + '-' + currentDay + ' 00:00');
 
            for (var i = 1; i <= 7; i++) {
                var sundayTiem = timestamp + (i - serverDate.getDay()) * 24 * 60 * 60 * 1000;
 
                var SundayData = new Date(sundayTiem);
 
                // 年
                var tomorrowY = SundayData.getFullYear();
 
                //月
 
                var tomorrowM = SundayData.getMonth() + 1 < 10 ? '0' + (SundayData.getMonth() + 1) : SundayData.getMonth() + 1;
 
                //日
 
                var tomorrowD = SundayData.getDate() < 10 ? '0' + SundayData.getDate() : SundayData.getDate();
 
                // console.log(tomorrowY + '-' + tomorrowM + '-' + tomorrowD);
 
                $('.supervise-patrol-duty-list .tbody tr:eq(' + (i - 1) + ') td:eq(1)').text(tomorrowY + '-' + tomorrowM + '-' + tomorrowD);
 
                if (tomorrowY + '-' + tomorrowM + '-' + tomorrowD == currentYear + '-' + currentMonth + '-' + currentDay) {
                    $('.supervise-patrol-duty-list .tbody tr:eq(' + (i - 1) + ')').addClass('on').siblings().removeClass('on');
                }
            }
        }
 
    });
});