zengh
2022-06-13 7973e449e74aab353d632e0db2937b376d45a6be
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
/**
 * 底图切换
 * @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",
    "dojo/dom-attr",
    "dojo/_base/lang"
], function(
    declare,
    BaseControl,
    template,
    domStyle,
    on,
    AppEvent,
    ConfigData,
    arrayUtil,
    domClass,
    domConstruct,
    mouse,
    dom,
    domAttr,
    lang
) {
    var Widget = declare("MapSwitchControl", [BaseControl], {
        templateString: template,
        visibleGroupLayerId: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() {
            return;
            this.inherited(arguments);
            var div = domConstruct.create("div",{id:"div_play"},this.container);
            var p_layer = domConstruct.create("div",{id:"p_layer"},div);
            var veclry = null;
            var imglry = null;
            arrayUtil.forEach(ConfigData.basemap.grouplayers, lang.hitch(this, function(item, index) {
                var thisObj = this;
                switch (item.id) {
                case "veclry":
                    veclry = domConstruct.create("dl",{
                        id:"veclry",
                        mapid:item.id,
                        style:"right:0px;"
                    },p_layer);
                    domConstruct.create("dt",{
                        innerHTML:"矢量",
                    },dom.byId("veclry"));
                    domConstruct.create("dd",{
                    },dom.byId("veclry"));
                    break;
                case "imglry":
                        imglry = domConstruct.create("dl",{
                            id:"imglry",
                            mapid:item.id,
                            class:"selected",
                            style:"right:0px;"
                        },p_layer);
                        domConstruct.create("dt",{
                            innerHTML:"影像",
                        },dom.byId("imglry"));
                        domConstruct.create("dd",{
                        },dom.byId("imglry"));
                        thisObj.label = "<img src='"+item.icon+"' class='ico'/>"+item.label;
                    break;
                }
            }));
            on(this, "mouseover", lang.hitch(this, function(evt) {    
                //if(this.id == "MapSwitchControl_0"){
                    //$('#MapSwitchControl_1').hide();
                //}
                  $("#"+this.id+" #imglry").stop(true);
                  $("#"+this.id+" #veclry").stop(true);
                  $("#"+this.id+" #imglry").animate({right: "0px"});
                  $("#"+this.id+" #veclry").animate({right: "90px"});
            }));
            on(p_layer, "mouseout", lang.hitch(this, function(evt) {                
                  $("#"+this.id+" #imglry").stop(true);
                  $("#"+this.id+" #veclry").stop(true);                  
                  $("#"+this.id+" #imglry").animate({right: "0px"});
                  $("#"+this.id+" #veclry").animate({right: "0px"});
                  //if("#MapSwitchControl_1"){
                    //    $('#MapSwitchControl_1').show();
                    //}
            }));
            on($("#"+this.id+" #p_layer dl" ), "click", lang.hitch(this, function(evt) {
                this._onMapDomClick(evt);
                $("#"+this.id+" #p_layer dl" ).removeClass('selected');
                $(evt.currentTarget).addClass("selected");
            }));
            
            if(this.visibleGroupLayerId){
                this._onMapDomClick({"currentTarget":veclry});
            }
        },
        /**
         * 隐藏地图类型的按钮,只显示一种可选按钮
         */
        _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);
        },
        _onGalleryDomMouseEnter:function(evt){
            var galleryName = domAttr.get(evt.currentTarget, "galleryid");
        },
        _onGalleryDomMouseLeave:function(evt){
            var galleryName = domAttr.get(evt.currentTarget, "galleryid");
        },
        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);
            }
        }
    });
    return Widget;
});