赣州市洪水风险预警系统二维版本
xiebin
2023-03-02 b39483c96ae572121d3c619c0b9d37634e682cc4
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
define(["base/AppEvent",
        "base/ConfigData",
        "dojo/_base/declare",
        "dojo/_base/lang",
        "dojo/dom",
        "dojo/dom-construct",
        "dojo/dom-attr",
        "dojo/dom-class",
        "dojo/on",
        "utils/LayerUtil",
        "utils/ConfigUtil",
        "controls/toolbar/tools/Map3DTool",
        "controls/toolbar/tools/MultidateTool",
        "controls/toolbar/tools/SwipeTool",
        "controls/toolbar/tools/ZoomInTool",
        "controls/toolbar/tools/ZoomOutTool",
        "controls/toolbar/tools/PanTool",
        "controls/toolbar/tools/FullScreenTool",
        "controls/toolbar/tools/ScreenWindowTool",
        "controls/toolbar/tools/StreetViewTool",
        "controls/toolbar/tools/MeasureLineTool",
        "controls/toolbar/tools/MeasurePolygonTool",
        "controls/toolbar/tools/ErrCorrectTool",
        "controls/toolbar/tools/ClearTool",
        "controls/toolbar/tools/CityLayerTool",
        "controls/toolbar/tools/LocationTool",
        "dojo/dom-style",
        "dojo/domReady!"
    ],
    function (AppEvent,
              ConfigData,
              declare,
              lang,
              dom,
              domConstruct,
              domAttr,
              domClass,
              on,
              LayerUtil,
              ConfigUtil,
              Map3DTool,
              MultidateTool,
              SwipeTool,
              ZoomInTool,
              ZoomOutTool,
              PanTool,
              FullScreenTool,
              ScreenWindowTool,
              StreetViewTool,
              MeasureLineTool,
              MeasurePolygonTool,
              ErrCorrectTool,
              ClearTool,
              CityLayerTool,
              LocationTool,
              domStyle) {
        return declare("WidgetManager", null, {
            //--------------------------------------------
            //  系统所有widget的配置
            //--------------------------------------------
            _widgetsConfig: [{
                "id": "IndexWidget", //Widget的ID
                "widgetClass": "widgets/index/IndexWidget", //Widget的url
                "cssPath": "widgets/index/IndexWidget.css", //Widget的css文件url
                "label": "专题地图", //Widget的显示名称,仅对sider类型有效
                "type": "sider", //Widget所属区域类型:sider,top,cover
                "actived": false //widget是否在初始化时加载,默认false,如果为false则只有AppEvent.RUN_WIDGET后才动态加载该widget。如果为sider类型,且displaylabel为true,不论改设置为true或false,都会在tabbar上创建该widget的按钮
                //"inited": true //提前初始化,避免其他组件与其互动时必须判断其是否已被初始化,actived为true时,inited无论如何都为true
            }, {
                "label": "洪水风险",
                "id": "RiskEarlyWarningBottomWidget",
                "widgetClass": "widgets/riskEarlyWarning/RiskEarlyWarningBottomWidget",
                "type": "sider",
                "cssPath": "widgets/riskEarlyWarning/RiskEarlyWarningBottomWidget.css",
                "actived": true
            }, {
                "label": "地图浏览",
                "id": "MapBrowseWidget",
                "widgetClass": "widgets/mapBrowse/MapBrowseWidget",
                "type": "sider",
                "cssPath": "widgets/mapBrowse/MapBrowseWidget.css",
                "actived": false
            },  {
                "label": "首页",
                "id": "homeWidget",
                "widgetClass": "widgets/home/homeWidget",
                "type": "sider",
                "cssPath": "widgets/home/homeWidget.css",
                "actived": false
            },  {
                "label": "登录",
                "id": "LoginWidget",
                "widgetClass": "widgets/login/LoginWidget",
                "type": "cover",
                "cssPath": "widgets/login/LoginWidget.css",
                "actived": false
            },{
                "label": "多时相",
                "id": "MultidateWidget",
                "widgetClass": "widgets/multidate/MultidateWidget",
                "type": "cover",
                "cssPath": "widgets/multidate/MultidateWidget.css",
                "actived": false
            }, {
                "label": "标记",
                "id": "SwipeWidget",
                "widgetClass": "widgets/swipe/SwipeWidget",
                "type": "cover",
                "cssPath": "widgets/swipe/SwipeWidget.css",
                "actived": false
            }, {
                "label": "统计分析",
                "id": "StatisticalWidget",
                "widgetClass": "widgets/Statistical/StatisticalWidget",
                "type": "sider",
                "cssPath": "widgets/Statistical/StatisticalWidget.css",
                "actived": false
            }, {
                "label": "统计图表",
                "id": "echartsWidget",
                "widgetClass": "widgets/echarts/echartsWidget",
                "type": "cover",
                "cssPath": "widgets/echarts/echartsWidget.css",
                "actived": false
            }, {
                "label": "统计图表-详细信息",
                "id": "detailsWidget",
                "widgetClass": "widgets/details/detailsWidget",
                "type": "cover",
                "cssPath": "widgets/details/detailsWidget.css",
                "actived": false
            }, {
                "label": "专题统计图",
                "id": "projectWidget",
                "widgetClass": "widgets/project/projectWidget",
                "type": "sider",
                "cssPath": "widgets/project/projectWidget.css",
                "actived": false
            },{
                "label": "地图查询_属性",
                "id": "attributeQueryWidget",
                "widgetClass": "widgets/attributeQuery/attributeQueryWidget",
                "cssPath": "widgets/attributeQuery/attributeQueryWidget.css",
                "type": "cover",
                "actived": false
            },{
                "label": "统计分析",
                "id": "StatisticsWidget",
                "widgetClass": "widgets/Statistics/StatisticsWidget",
                "type": "sider",
                "cssPath": "widgets/Statistics/StatisticsWidget.css",
                "actived": false
            }, {
                "label": "空间分析_叠加分析",
                "id": "SpaceWidget",
                "widgetClass": "widgets/space/SpaceWidget",
                "type": "sider",
                "cssPath": "widgets/space/SpaceWidget.css",
                "actived": false
            }, {
                "label": "空间分析_缓冲区",
                "id": "bufferWidget",
                "widgetClass": "widgets/buffer/bufferWidget",
                "type": "sider",
                "cssPath": "widgets/buffer/bufferWidget.css",
                "actived": false
            }],
            _map: null,
            _bodyDom: null,
            _mapContentDom: null,
            /**
             * 默认初始化显示在侧边栏的Widget
             */
            _defaultActivedSiderWidgetId: null,
            _topWidgetContainerDom: null,
            _widgetsTable: {},
            _activedButton: null,
            _widgetId2TabButtonIndex: {},
            constructor: function () {
                AppEvent.addAppEventListener(AppEvent.CONFIG_LOADED, lang.hitch(this, this.onConfigLoaded));
                AppEvent.addAppEventListener(AppEvent.BASE_MAP_LAYER_LOADED, lang.hitch(this, this.onMapLoaded));
                AppEvent.addAppEventListener(AppEvent.RUN_WIDGET, lang.hitch(this, this.onRunWidgetHandler));
                AppEvent.addAppEventListener(AppEvent.CLOSE_WIDGET, lang.hitch(this, this.onCloseWidgetHandler));
            },
            onConfigLoaded: function () {
                this._bodyDom = dom.byId("body");
                this._mapContentDom = dom.byId("mapcontentClass");
                this._topWidgetContainerDom = dom.byId("topWidgetContainer");
            },
            onMapLoaded: function (map) {
                try {
                    this._map = map;
                    for (var i = 0; i < this._widgetsConfig.length; i++) {
                        var widgetCfg = this._widgetsConfig[i];
                        switch (widgetCfg.type) {
                            case "sider":
                                this._parseSiderWidget(widgetCfg);
                                break;
                            case "top":
                                this._parseTopWidget(widgetCfg);
                                break;
                            case "cover":
                                this._parseCoverWidget(widgetCfg);
                                break;
                        }
                    }
                    if (this._defaultActivedSiderWidgetId != null && this._activedButton != null) {
                        this._switchTab(this._defaultActivedSiderWidgetId);
                        domClass.add(this._activedButton, "tabbuttonbar-actived");
                    }
                    this._tempAppendOthers();
                } catch (err) {
                    console.log(err);
                }
 
            },
            /**
             * 解析侧边栏的Widget
             */
            _parseSiderWidget: function (widgetCfg) {
                if (widgetCfg.inited) {
                    this._loadWidget(widgetCfg.widgetClass, widgetCfg.id, widgetCfg.cssPath, function (widget) {
                        domConstruct.place(widget.domNode, dom.byId("tabcontainer"));
                        widget.startup();
                        widget.close();
                    });
                }
//                if (!widgetCfg.displaylabel) {
//
//                    return
//                }
                var tabButton = domConstruct.create("li", null, dom.byId("tabbuttonbar"));
                on(tabButton, "click", dojo.hitch(this, this._onTabButtonClickHandler));
                domAttr.set(tabButton, "widgetid", widgetCfg.id);
                if (widgetCfg.actived) {
                    this._defaultActivedSiderWidgetId = widgetCfg.id;
                    this._activedButton = tabButton;
                }
                tabButton.innerHTML = widgetCfg.label;
                this._widgetId2TabButtonIndex[widgetCfg.id] = tabButton;
            },
            /**
             * 解析顶部位置的Widget
             */
            _parseTopWidget: function (widgetCfg) {
                if (widgetCfg.actived) {
                    this._loadWidget(widgetCfg.widgetClass, widgetCfg.id, widgetCfg.cssPath, lang.hitch(this, function () {
                        var widget = this._widgetsTable[widgetCfg.id];
                        domConstruct.place(widget.domNode, this._topWidgetContainerDom);
                        widget.startup();
                        widget.open();
                    }));
                }
            },
            /**
             * 解析浮动在地图显示区域上的Widget
             */
            _parseCoverWidget: function (widgetCfg) {
                if (widgetCfg.actived) {
                    this._loadWidget(widgetCfg.widgetClass, widgetCfg.id, widgetCfg.cssPath, lang.hitch(this, function () {
                        var widget = this._widgetsTable[widgetCfg.id];
                        domConstruct.place(widget.domNode, this._mapContentDom);
                        widget.startup();
                    }));
                }
 
            },
 
            onRunWidgetHandler: function (widgetId) {
                var widgetCfg = this._getWidgetConfigById(widgetId);
                if (!widgetCfg) {
                    alert("该模块不存在!");
                    return;
                }
                var widget = this._widgetsTable[widgetId];
                if (widget == null) {
                    var content = {
                        thisObj: this,
                        widgetCfg: widgetCfg
                    };
                    this._loadWidget(widgetCfg.widgetClass, widgetId, widgetCfg.cssPath, lang.hitch(content, function () {
                        var widget = this.thisObj._widgetsTable[this.widgetCfg.id];
                        this.thisObj._runWidget(widget, this.widgetCfg);
                    }));
                } else {
                    this._runWidget(widget, widgetCfg);
                }
            },
            onCloseWidgetHandler: function (widgetId) {
                var widgetCfg = this._getWidgetConfigById(widgetId);
                if (!widgetCfg) {
                    return;
                }
                var widget = this._widgetsTable[widgetId];
                if (!widget) {
                    return;
                }
                widget.close();
            },
 
            /**
             * 运行Widget
             */
            _runWidget: function (widget, widgetCfg) {
                switch (widgetCfg.type) {
                    case "sider":
                        if (this._activedButton) {
                            domClass.remove(this._activedButton, "tabbuttonbar-actived");
                        }
                        this._switchTab(widgetCfg.id);
                        this._activedButton = null;
                        if (widgetCfg.displaylabel) {
                            this._activedButton = this._widgetId2TabButtonIndex[widgetCfg.id];
                            domClass.add(this._activedButton, "tabbuttonbar-actived");
                        }
                        break;
                    case "top":
                        this._parseTopWidget(widgetCfg);
                        if (widget.loaded() == false) {
                            widget.startup();
                        }
                        widget.open();
                        break;
                    case "cover":
                        //this._parseCoverWidget(widgetCfg);
                        domConstruct.place(widget.domNode, this._mapContentDom);
                        if (widget.loaded() == false) {
                            widget.startup();
                        }
                        widget.open();
                        break;
                }
                //会导致对sider widget派发RUNWIDGET事件时,widget.open()执行两次,故移入switch中 。  Edit by liuyl 2015/11/5
                //                if (widget.loaded() == false) {
                //                    widget.startup();
                //                }
                //                widget.open();
            },
            /**
             * 临时的实例化,因为还没有规划好怎么加载
             */
            _tempAppendOthers: function () {
                var map = this._map;
                var mapDomNode = dom.byId(map.id);
                //创建常用工具条
                dojo.create("link", {
                        href: 'controls/toolbar/toolbar.css',
                        type: 'text/css',
                        rel: 'stylesheet'
                    },
                    document.getElementsByTagName('head')[0]);
                var toolbarDom = domConstruct.create("div", {
                    id: "toolBarDiv",
                    "class": "toolbar"
                }, dom.byId('mainMapWidget'));
 
                // var tool = new LocationTool({
                //     "map": this._map
                // });
                // domConstruct.place(tool.domNode, toolbarDom);
                // AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                //     tool: tool,
                //     hockId: ConfigData.mapWidgetId
                // });
 
                // var tool = new MultidateTool({
                //     "map": this._map
                // });
                // domConstruct.place(tool.domNode, toolbarDom);
                // AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                //     tool: tool,
                //     hockId: ConfigData.mapWidgetId
                // });
 
                var tool = new PanTool({
                    "map": this._map
                });
                domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: tool,
                    hockId: ConfigData.mapWidgetId
                });
 
                var tool = new MeasureLineTool({
                    "map": this._map
                });
                domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: tool,
                    hockId: ConfigData.mapWidgetId
                });
 
                var tool = new MeasurePolygonTool({
                    "map": this._map
                });
                domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: tool,
                    hockId: ConfigData.mapWidgetId
                });
 
 
                /*var tool = new Map3DTool({
                    "map": this._map
                });
                domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: tool,
                    hockId: ConfigData.mapWidgetId
                });*/
 
                // var tool = new MultidateTool({
                //     "map": this._map
                // });
                // domConstruct.place(tool.domNode, toolbarDom);
                // AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                //     tool: tool,
                //     hockId: ConfigData.mapWidgetId
                // });
                //地图标记
                var tool = new SwipeTool({
                    "map": this._map
                });
                domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: tool,
                    hockId: ConfigData.mapWidgetId
                });
 
                /*var streetviewtool = new StreetViewTool({
                    "map": this._map
                });
                domConstruct.place(streetviewtool.domNode, this._mapContentDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, tool);
                var content = {
                    tool: streetviewtool
                }
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: streetviewtool,
                    hockId: ConfigData.mapWidgetId
                });*/
 
                /*                var tool = new ScreenWindowTool({
                                    "map": this._map
                                });
                                domConstruct.place(tool.domNode, toolbarDom);
                                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, tool);*/
 
                /*var tool = new ErrCorrectTool({
                    "map": this._map
                });*/
                /*domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, tool);*/
 
                /*var tool = new FullScreenTool({
                    "map": this._map
                });
                domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, tool);
                on(closeStreetViewButton, "click", lang.hitch(content, function() {
                    this.tool.deactivate();
                }));*/
 
                /*var tool = new CityLayerTool({
                    "map": this._map
                });*/
                /*domConstruct.place(tool.domNode, this._mapContentDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: tool,
                    hockId: ConfigData.mapWidgetId
                });*/
 
                var tool = new ClearTool({
                    "map": this._map
                });
                domConstruct.place(tool.domNode, toolbarDom);
                AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, {
                    tool: tool,
                    hockId: ConfigData.mapWidgetId
                });
 
            },
            _onTabButtonClickHandler: function (evt) {
                if (this._activedButton == evt.currentTarget) {
                    return;
                }
                var clickButton = evt.currentTarget;
                var widgetId = domAttr.get(evt.currentTarget, "widgetid");
                var widget = this._widgetsTable[widgetId];
                if (widget == null) {
                    //Widget还未Load
                    var widgetCfg = this._getWidgetConfigById(widgetId);
                    this._loadWidget(widgetCfg.widgetClass, widgetId, widgetCfg.cssPath, lang.hitch(this, function () {
                        widget = this._widgetsTable[widgetId];
                        //this._confirmUserRightForSiderWidget(widget)
                        if (this._activedButton) {
                            domClass.remove(this._activedButton, "tabbuttonbar-actived");
                        }
                        this._switchTab(widget.widgetName);
                        this._activedButton = clickButton;
                        domClass.add(this._activedButton, "tabbuttonbar-actived");
                    }));
                } else {
                    //this._confirmUserRightForSiderWidget(widget)
                    if (this._activedButton) {
                        domClass.remove(this._activedButton, "tabbuttonbar-actived");
                    }
                    this._switchTab(widget.widgetName);
                    this._activedButton = clickButton;
                    domClass.add(this._activedButton, "tabbuttonbar-actived");
                }
                //var loadwidget = lang.hitch(this, this._confirmUserRightForSiderWidget(widget));
            },
            _switchTab: function (widgetId) {
                var widget;
                if (widgetId == this._defaultActivedSiderWidgetId) {
                    //第一次加载defaultWidget的时候,widget还未请求
                    widget = this._widgetsTable[widgetId];
                    if (widget != null) {
                        return;
                    }
                    //是第一次加载,先清除default,以可以走下面的判断
                    this._defaultActivedSiderWidgetId = null;
                }
                if (this._defaultActivedSiderWidgetId != null) {
                    widget = this._widgetsTable[this._defaultActivedSiderWidgetId];
                    widget.close();
                    widget.domNode.parentNode.removeChild(widget.domNode);
                }
                widget = this._widgetsTable[widgetId];
                var loadfun = lang.hitch(this, function (widget, widgetId) {
                    this._defaultActivedSiderWidgetId = widgetId;
                    domConstruct.place(widget.domNode, dom.byId("tabcontainer"));
                    if (widget.loaded() == false) {
                        widget.startup();
                    }
 
                    widget.open();
                });
                if (widget == null) {
                    var widgetCfg = this._getWidgetConfigById(widgetId);
                    this._loadWidget(widgetCfg.widgetClass, widgetId, widgetCfg.cssPath, lang.hitch(this, function () {
                        widget = this._widgetsTable[widgetId];
                        loadfun(widget, widgetId);
                    }));
                } else {
                    loadfun(widget, widgetId);
                }
 
            },
            _loadWidget: function (widgetUrl, widgetId, cssPath, callback) {
                if (cssPath && cssPath != "") {
                    dojo.create("link", {
                            href: cssPath,
                            type: "text/css",
                            rel: "stylesheet"
                        },
                        document.getElementsByTagName("head")[0]);
                }
                require([widgetUrl], lang.hitch(this, function (WidgetClass) {
                        var widget = new WidgetClass({
                            map: this._map,
                            id: widgetId
                        });
                        this._widgetsTable[widgetId] = widget;
                        if (callback)
                            callback(widget);
                    }),
                    function (err) {
                        console.log("load widget");
                        console.log(err);
                    });
            },
            _getWidgetConfigById: function (widgetId) {
                for (var i = 0; i < this._widgetsConfig.length; i++) {
                    if (this._widgetsConfig[i].id == widgetId) {
                        return this._widgetsConfig[i];
                    }
                }
            }
        });
    });