ArcGIS For JavaScript API Switch Basemap(切换底图)

描述:

可切换地图地图,使用BasemapGallery类默认选择项

 

您可以添加其他的底图的图库,但所有底图添加到BasemapGallery,需要在相同的投影。如果要显示底图从和ArcGIS.com,showArcGISBasemaps=True 那么其他的底图必须在Web墨卡托投影。

所有底图添加到画廊需要具有相同的空间参考。如果使用默认的ArcGIS.com底图添加到库中所有的其他项目需要是在Web墨卡托(wkids:102100,102113,3857)。如果不使用默认的底图,您可以添加底图,只要在任何空间参考,因为所有的项目添加到库共享空间参考。为了达到最佳性能,建议所有的画廊底图缓存层(平铺)。

 

代码如下:

[html]  view plain copy print ?
  1. <!DOCTYPE html>  
  2.   <html>    
  3.   <head>   
  4.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5.     <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">  
  6.     <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices-->  
  7.     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>  
  8.     <title></title>  
  9.   
  10.     <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dijit/themes/claro/claro.css">      
  11.     <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">  
  12.     <style>   
  13.       html, body { height: 100%; width: 100%; margin: 0; padding: 0; }  
  14.       #map{  
  15.         padding:0;  
  16.       }  
  17.     </style>   
  18.       
  19.     <script>  
  20.         var dojoConfig = {   
  21.             parseOnLoad: true   
  22.         };  
  23.     </script>  
  24.     <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>  
  25.     <script>   
  26.         // 导入包  
  27.         dojo.require("dijit.layout.BorderContainer");  
  28.         dojo.require("dijit.layout.ContentPane");  
  29.         dojo.require("esri.map");  
  30.         dojo.require("esri.virtualearth.VETiledLayer"); // Bing地图tiled层,在2.0中,Bing地图是一个Key  
  31.         dojo.require("dijit.TitlePane");  
  32.         dojo.require("esri.dijit.BasemapGallery");  
  33.         dojo.require("esri.arcgis.utils");  
  34.         
  35.         var map;  
  36.   
  37.       function init() {  
  38.         var initExtent = new esri.geometry.Extent({  
  39.             "xmin":-11727455,   // 左下角X坐标  
  40.             "ymin":4861652,     // 左下角Y坐标  
  41.             "xmax":-11706340,   // 右上角X坐标  
  42.             "ymax":4871512,     // 右上角Y坐标  
  43.             "spatialReference":{    // 空间参考  
  44.                 "wkid":102100  
  45.             }  
  46.         });  
  47.         map = new esri.Map("map", {  
  48.             basemap: "topo",  // 指定的地图底图。以下是有效选项:"streets","satellite","hybrid","topo","gray","oceans","national-geographic","osm".  
  49.             center: [-105.255, 40.022], // 地图居中经纬度  
  50.             zoom: 13    // 缩放级别  
  51.         });  
  52.   
  53.         // 添加地图图库,在这种情况下,我们会从 ArcGIS.com中包括Bing maps去显示  
  54.         var basemapGallery = new esri.dijit.BasemapGallery({  
  55.           showArcGISBasemaps: true, // 可选.如果为true:查询ArcGIS.com来检索可底图 false:只有指定的用户自定义的底图使用的底图属性被显示出来  
  56.           bingMapsKey: 'Ah29HpXlpKwqVbjHzm6mlwMwgw69CYjaMIiW_YOdfTEMFvMr5SNiltLpYAcIocsi',  // 可选 指定你的Bing地图密钥 Bing地图关键是如果没有提供Bing地图类型将不会显示在BasemapGallery  
  57.           map: map  // 必选,指定地图对象  
  58.         }, "basemapGallery");  
  59.         basemapGallery.startup();   // 开启  
  60.           
  61.         dojo.connect(basemapGallery, "onError", function(msg) {console.log(msg);alert(msg)});   // 失败时触发  
  62.       }  
  63.       dojo.ready(init);  
  64.     </script>   
  65.   </head>   
  66.   
  67.   <body class="claro">   
  68.     <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;margin:0;">  
  69.       <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'" style="padding:0;">  
  70.         <div style="position:absolute; right:20px; top:10px; z-Index:999;">  
  71.           <div data-dojo-type="dijit.TitlePane" data-dojo-props="title:'切换底图', closable:false,  open:false">  
  72.             <div data-dojo-type="dijit.layout.ContentPane" style="width:380px; height:280px; overflow:auto;">  
  73.                 <div id="basemapGallery" ></div>  
  74.             </div>  
  75.           </div>  
  76.         </div>  
  77.       </div>  
  78.     </div>  
  79.   </body>   
  80. </html>  


切换底图效果图

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值