天地图的底图控件默认选中问题

方法一:maptype 控件,通过加载图层顺序可以默认选中,一般是默认选中第一个,但是如果“TMAP_NORMAL_MAP”,都会默认为这个选中;可参考方法二

如:

this.ctrl = new T.Control.MapType([
              {
                title: "卫星混合",
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/satellitepoi.png",
                layer: TMAP_HYBRID_MAP
              },{
                title: "地图", //地图控件上所要显示的图层名称
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/vector.png", //地图控件上所要显示的图层图标(默认图标大小80x80)
                layer: TMAP_NORMAL_MAP //地图类型对象,即MapType。
              }, {
                title: "地形混合",
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrainpoi.png",
                layer: TMAP_TERRAIN_HYBRID_MAP
              },{
                title: "工业用地最低价标准",
                icon:"http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrain.png",
                layer: this.wmsLayer_gyyd
              }
            ]);
            this.map.addControl(this.ctrl)

 

 

如果没有“TMAP_NORMAL_MAP ”地图的话就会按照顺序默认选中第一个

this.ctrl = new T.Control.MapType([
              {
                title: "卫星混合",
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/satellitepoi.png",
                layer: TMAP_HYBRID_MAP
              }, {
                title: "地形混合",
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrainpoi.png",
                layer: TMAP_TERRAIN_HYBRID_MAP
              },{
                title: "工业用地最低价标准",
                icon:"http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrain.png",
                layer: this.wmsLayer_gyyd
              }
            ]);
            this.map.addControl(this.ctrl);
            this.ctrl.setPosition(T_ANCHOR_BOTTOM_RIGHT);

 

 

 

 方法二:

如果  maptype控件有““TMAP_NORMAL_MAP ””,但是又不想默认选中“TMAP_NORMAL_MAP ”,则默认 map.config 有layer,则默认它是最先加载的

 

var imageURL = "http://t0.tianditu.gov.cn/img_c/wmts?" +
"SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=c&FORMAT=tiles" +
"&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=您的密钥";
//创建自定义图层对象
lay = new T.TileLayer(imageURL, {minZoom: 1, maxZoom: 18});
var config = {layers: [lay]};  //要默认选中的底图, maptype里也要放到第一个 
//初始化地图对象
this.map = new T.Map("mapDiv", config);

 

this.ctrl = new T.Control.MapType([
              {
                title: "卫星混合",
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/satellitepoi.png",
                layer: TMAP_HYBRID_MAP
              },{
                title: "地图", //地图控件上所要显示的图层名称
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/vector.png", //地图控件上所要显示的图层图标(默认图标大小80x80)
                layer: TMAP_NORMAL_MAP //地图类型对象,即MapType。
              }, {
                title: "地形混合",
                icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrainpoi.png",
                layer: TMAP_TERRAIN_HYBRID_MAP
              },{
                title: "工业用地最低价标准",
                icon:"http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrain.png",
                layer: this.wmsLayer_gyyd
              }
            ]);
            this.map.addControl(this.ctrl)
 

 

 

 

 
posted @ 2022-06-10 17:16  小鱼写代码的过往  阅读(580)  评论(0编辑  收藏  举报