赣州市洪水风险预警系统二维版本
xiebin
2023-02-24 ec1a74625890ff771fc5e46e39a15deaf618b479
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
/**
 * 底图切换
 * @author Wenyb
 * @date 2015/6/29
 */
define([
    "dojo/_base/declare",
    "base/BaseControl",
    "dojo/text!controls/mapswitch/MapSwitchControl.html",
    "dojo/dom-style",
    "dojo/on",
    "base/AppEvent",
    "base/ConfigData",
    "dojo/_base/array",
    "dojo/dom-class",
    "dojo/dom-construct",
    "dojo/mouse",
    "dojo/dom-attr",
    "dojo/_base/lang"
], function(
    declare,
    BaseControl,
    template,
    domStyle,
    on,
    AppEvent,
    ConfigData,
    arrayUtil,
    domClass,
    domConstruct,
    mouse,
    domAttr,
    lang) {
    var Widget = declare("MapSwitchControl", [BaseControl], {
        templateString: template,
        visibleGroupLayerId:null,
        visibleLayerSetId:null,
        constructor: function(options) {
            this.inherited(arguments);
            declare.safeMixin(this, options);
            this._grouplayers = [];
            this._currentVisibleLayerlabel = null;
            this.base_class = "mapswitch-container";
            this._galleryDomTable = {};
            this._maps2galleryTable = {};
            this._galleryLeaveHandlerTable = {};
            var baseMaps = ConfigData.basemap.grouplayers;
            for (var key in baseMaps) {
                var gl = baseMaps[key];
                if (gl.visible == true) {
                    this._currentVisibleLayerlabel = gl.label;
                }
                this._grouplayers.push(gl.label);
            }
            this.gallery = ConfigData.basemap.gallerys[0];
            this.groups = ConfigData.basemap.grouplayers;
            this.index = [];
            this.galleryDom = null;
            AppEvent.addAppEventListener(AppEvent.SWITCH_BASEMAP, lang.hitch(this, this.onSwitchBaseMapHandler));
        },
        startup: function() {
            this.inherited(arguments);
            var tableDom = domConstruct.create("table", {}, this.container);
            domStyle.set(tableDom, "border-spacing", "0px 5px");
            domStyle.set(tableDom, "margin", "0px");
            arrayUtil.forEach(ConfigData.basemap.gallerys, lang.hitch(this, function(item, index) {
                var trDom = domConstruct.create("tr", {
                    "galleryid": item.id
                }, tableDom);
                var tdDom = domConstruct.create("td", {
                    "galleryid": item.id
                }, trDom);
                domClass.add(tdDom, "mapswitch-td");
                this._galleryDomTable[item.id] = tdDom;
                this._maps2galleryTable[item.id] = [];
                this._galleryLeaveHandlerTable[item.id] = null;
                on(tdDom, mouse.enter, lang.hitch(this,this._onGalleryDomMouseEnter));
                on(tdDom, mouse.leave, lang.hitch(this, this._onGalleryDomMouseLeave));
            }));
 
            //构建每个地图集里面的子项
            arrayUtil.forEach(ConfigData.basemap.grouplayers, lang.hitch(this, function(item, index) {
                var styleValue = "background:url('" + item.icon + "') center 2px no-repeat #ffffff;margin-right:5px";
                var mapDom = domConstruct.create("div", {
                    "mapid": item.id,
                    "class":"mapswitch-div",
                    "style":styleValue,
                    "title":"切换到"+item.label
                });
                on(mapDom, "click", lang.hitch(this, this._onMapDomClick));
                var mapNameDom = domConstruct.create("span", {
                    "innerHTML": item.label,
                    "class":"mapswitch-mapname"
                }, mapDom);
                var gallerytdDom = this._galleryDomTable[item.gallery];
                this._maps2galleryTable[item.gallery].push(mapDom);
                domConstruct.place(mapDom, gallerytdDom);
                if(this.visibleGroupLayerId){
                    domAttr.set(gallerytdDom,"visibleGroupLayerId",this.visibleGroupLayerId);
                }else if(item.visible){
                    domAttr.set(gallerytdDom,"visibleGroupLayerId",item.id);
                }
                
            }));
            arrayUtil.forEach(ConfigData.basemap.gallerys, lang.hitch(this, function(item, index){
                this._hideGalleryDomByVisibleMap(item.id);
            }));
        },
        /**
         * 隐藏地图类型的按钮,只显示一种可选按钮
         */
        _hideGalleryDomByVisibleMap:function(galleryId){
            var gallerytdDom = this._galleryDomTable[galleryId];
            var visibleLayer = domAttr.get(gallerytdDom,"visibleGroupLayerId");
            var mapDoms=this._maps2galleryTable[galleryId];
            var hasShowLayer=false;//是否已经显示了一个备选的图层按钮,如果已显示,则其他的都不再显示。
            arrayUtil.forEach(mapDoms,function(item,index){
                if(domAttr.get(item,"mapid")==visibleLayer){
                    domStyle.set(item,"display","none");
                    return;
                }
                if(hasShowLayer){
                    domStyle.set(item,"display","none");
                }else{
                    domStyle.set(item,"display","block");
                    hasShowLayer=true;
                }
            });
        },
        _showGalleryDomByVisibleMap:function(galleryId){
            var gallerytdDom = this._galleryDomTable[galleryId];
            var visibleLayer = domAttr.get(gallerytdDom,"visibleGroupLayerId");
            var mapDoms=this._maps2galleryTable[galleryId];
            var hasShowLayer=false;//是否已经显示了一个备选的图层按钮,如果已显示,则其他的都不再显示。
            arrayUtil.forEach(mapDoms,function(item,index){
                // if(domAttr.get(item,"mapid")==visibleLayer){
                //     domStyle.set(item,"display","none");
                //     return;
                // }
                domStyle.set(item,"display","block");
                hasShowLayer=true;
            });
        },
        _onMapDomClick:function(evt) {
            var mapid = domAttr.get(evt.currentTarget, "mapid");
        
            AppEvent.dispatchAppEvent(AppEvent.SWITCH_BASEMAP, {
                hockId: this.hockId,
                grouplayer: mapid,
                sender:this.id
            });
            var galleryId=domAttr.get(evt.currentTarget.parentNode,"galleryid");
            domAttr.set(evt.currentTarget.parentNode,"visibleGroupLayerId",mapid);
            if (mapid == 'imglry') {
                this.map._layers.cia.opacity = 1
            } else {
                this.map._layers.cia.opacity = 0
            }
            this._hideGalleryDomByVisibleMap(galleryId);
        },
        _onGalleryDomMouseEnter:function(evt){
            var galleryName = domAttr.get(evt.currentTarget, "galleryid");
            this._showGalleryDomByVisibleMap(galleryName);
        },
        _onGalleryDomMouseLeave:function(evt){
            var galleryName = domAttr.get(evt.currentTarget, "galleryid");
            this._hideGalleryDomByVisibleMap(galleryName);
        },
        onSwitchBaseMapHandler:function(evt){
            if(this.id == evt.sender){
                return;
            }
            if (evt.hockId != this.hockId)
                return;
            for(var key in this._galleryDomTable){
                domAttr.set(this._galleryDomTable[key],"visibleGroupLayerId",evt.grouplayer);
                this._hideGalleryDomByVisibleMap(key);
            }
        }
    });
    return Widget;
});