zhongrj
2023-06-27 d74b495736f0c04522ec54274b70fed0ded2878d
public/map/controls/mapswitch/MapSwitchControl.js
New file
@@ -0,0 +1,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;
});