Arcgis for js加载百度地图

在Arcgis for js中加载百度地图。
 
效果:
0
 
地图
0
 
影像-无标注
0
 
影像-有标注
 
实现:
第一,在此感谢http://www.cnblogs.com/chenyuming507950417/p/3343729.html这篇文章的主人,给了我很大的启发与帮助,因为一直在找相关的参数,都不对,只有这个参数是没有问题的。
 
第二,百度地图可调用的有地图切片,影像切片,以及道路等POI切片,我将之用TiledMapServiceLayer做了扩展,成了BDAnoLayer,BDVecLayer,BDimgLayer三个图层,其代码如下:
BDAnoLayer.js
 
  1. define(["dojo/_base/declare",  
  2.     "esri/layers/tiled"],  
  3.     function (declare) {  
  4.         return declare(esri.layers.TiledMapServiceLayer, {  
  5.             constructor: function () {  
  6.                 this.spatialReference = new esri.SpatialReference({ wkid: 102100 });  
  7.                 this.initialExtent = (this.fullExtent = new esri.geometry.Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));  
  8.                 this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,  
  9.                     4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,  
  10.                     36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];  
  11.                 this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,  
  12.                     1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,  
  13.                     4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];  
  14.                 this.tileInfo = new esri.layers.TileInfo({  
  15.                     "rows": 256,  
  16.                     "cols": 256,  
  17.                     "compressionQuality": 90,  
  18.                     "origin": {  
  19.                         "x": -20037508.3427892,  
  20.                         "y": 20037508.3427892  
  21.                     },  
  22.                     "spatialReference": this.spatialReference,  
  23.                     "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },  
  24.                         { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },  
  25.                         { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },  
  26.                         { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },  
  27.                         { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },  
  28.                         { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },  
  29.                         { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },  
  30.                         { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },  
  31.                         { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },  
  32.                         { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },  
  33.                         { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },  
  34.                         { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },  
  35.                         { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },  
  36.                         { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },  
  37.                         { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },  
  38.                         { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },  
  39.                         { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },  
  40.                         { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },  
  41.                         { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },  
  42.                         { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }  
  43.                     ]  
  44.                 });  
  45.                 this.loaded = true;  
  46.                 this.onLoad(this);  
  47.             },  
  48.             getTileUrl: function (level, row, col) {  
  49.                 var zoom = level - 1;  
  50.                 var offsetX = parseInt(Math.pow(2, zoom));  
  51.                 var offsetY = offsetX - 1;  
  52.                 var numX = col - offsetX, numY = (-row) + offsetY ;  
  53.                 var num = (col + row) % 8 + 1;  
  54.                 return "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=sl&udt=20141015";  
  55.             }  
  56.         });  
  57.     });  
BDVecLayer.js
[javascript] view plain copy
0
0
  1. define(["dojo/_base/declare",  
  2.     "esri/layers/tiled"],  
  3.     function (declare) {  
  4.         return declare(esri.layers.TiledMapServiceLayer, {  
  5.             constructor: function () {  
  6.                 this.spatialReference = new esri.SpatialReference({ wkid: 102100 });  
  7.                 this.initialExtent = (this.fullExtent = new esri.geometry.Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));  
  8.                 this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,  
  9.                     4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,  
  10.                     36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];  
  11.                 this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,  
  12.                     1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,  
  13.                     4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];  
  14.                 this.tileInfo = new esri.layers.TileInfo({  
  15.                     "rows": 256,  
  16.                     "cols": 256,  
  17.                     "compressionQuality": 90,  
  18.                     "origin": {  
  19.                         "x": -20037508.3427892,  
  20.                         "y": 20037508.3427892  
  21.                     },  
  22.                     "spatialReference": this.spatialReference,  
  23.                     "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },  
  24.                         { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },  
  25.                         { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },  
  26.                         { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },  
  27.                         { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },  
  28.                         { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },  
  29.                         { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },  
  30.                         { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },  
  31.                         { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },  
  32.                         { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },  
  33.                         { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },  
  34.                         { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },  
  35.                         { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },  
  36.                         { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },  
  37.                         { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },  
  38.                         { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },  
  39.                         { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },  
  40.                         { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },  
  41.                         { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },  
  42.                         { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }  
  43.                     ]  
  44.                 });  
  45.                 this.loaded = true;  
  46.                 this.onLoad(this);  
  47.             },  
  48.             getTileUrl: function (level, row, col) {  
  49.                 var zoom = level - 1;  
  50.                 var offsetX = parseInt(Math.pow(2, zoom));  
  51.                 var offsetY = offsetX - 1;  
  52.                 var numX = col - offsetX, numY = (-row) + offsetY ;  
  53.                 var num = (col + row) % 8 + 1;  
  54.                 return "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=pl&scaler=1&udt=20141103";  
  55.             }  
  56.         });  
  57.     });  
BDimgLayer.js
[javascript] view plain copy
0
0
  1. define(["dojo/_base/declare",  
  2.     "esri/layers/tiled"],  
  3.     function (declare) {  
  4.         return declare(esri.layers.TiledMapServiceLayer, {  
  5.             constructor: function () {  
  6.                 this.spatialReference = new esri.SpatialReference({ wkid: 102100 });  
  7.                 this.initialExtent = (this.fullExtent = new esri.geometry.Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));  
  8.                 this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,  
  9.                     4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,  
  10.                     36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];  
  11.                 this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,  
  12.                     1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,  
  13.                     4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];  
  14.                 this.tileInfo = new esri.layers.TileInfo({  
  15.                     "rows": 256,  
  16.                     "cols": 256,  
  17.                     "compressionQuality": 90,  
  18.                     "origin": {  
  19.                         "x": -20037508.3427892,  
  20.                         "y": 20037508.3427892  
  21.                     },  
  22.                     "spatialReference": this.spatialReference,  
  23.                     "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },  
  24.                         { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },  
  25.                         { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },  
  26.                         { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },  
  27.                         { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },  
  28.                         { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },  
  29.                         { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },  
  30.                         { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },  
  31.                         { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },  
  32.                         { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },  
  33.                         { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },  
  34.                         { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },  
  35.                         { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },  
  36.                         { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },  
  37.                         { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },  
  38.                         { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },  
  39.                         { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },  
  40.                         { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },  
  41.                         { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },  
  42.                         { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }  
  43.                     ]  
  44.                 });  
  45.                 this.loaded = true;  
  46.                 this.onLoad(this);  
  47.             },  
  48.             getTileUrl: function (level, row, col) {  
  49.                 var zoom = level - 1;  
  50.                 var offsetX = parseInt(Math.pow(2, zoom));  
  51.                 var offsetY = offsetX - 1;  
  52.                 var numX = col - offsetX, numY = (-row) + offsetY ;  
  53.                 var num = (col + row) % 8 + 1;  
  54.                 return "http://shangetu" + num + ".map.bdimg.com/it/u=x="+numX+";y="+numY+";z="+level+";v=009;type=sate&fm=46&udt=20141015";  
  55.             }  
  56.         });  
  57.     });  
从上面的getTileUrl可以看到,三者返回的url的地址是有区别的,在上述那边博文里面提到的url已经失效,为了得到最新的地址,我做了如下工作:
1、用百度地图JS API调用并显示百度地图,代码如下:
[html] view plain copy
0
0
  1. >  
  2.   
  3.   
  4.     <meta< span=""> http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.     <meta< span=""> name="viewport" content="initial-scale=1.0, user-scalable=no" />  
  6.     <style< span=""> type="text/css">  
  7.         body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}  
  8.       
  9.     <script< span=""> type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的秘钥">  
  10.       
  11.   
  12.   
  13. <div< span=""> id="allmap">
  
  •   
  •   
  • <script< span=""> type="text/javascript">  
  •     // 百度地图API功能  
  •     var map = new BMap.Map("allmap");    // 创建Map实例  
  •     map.centerAndZoom(new BMap.Point(116.404, 39.915), 5);  // 初始化地图,设置中心点坐标和地图级别  
  •     map.addControl(new BMap.MapTypeControl());   //添加地图类型控件  
  •     map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的  
  •     map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放  
  •   
2、F12打开Chrom调试——NetWork——左边找一张切片,右边切换至Preview面板
0
 
地图url
0
 
影像url
0
 
poi url
如此,URL即为切片的Url,其中online后面的数字2即为代码中的num,x为代码中的numX,y为numY,z为缩放级别。
 
第三,调用显示
调用显示比较简单,代码如下:
[html] view plain copy
0
0
  1. >  
  2.   
  3.   
  4.     <meta< span=""> http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5.       
  6.     <link< span=""> rel="stylesheet" href="http://localhost/arcgis_js_api/library/3.9/3.9/js/dojo/dijit/themes/tundra/tundra.css">  
  7.     <link< span=""> rel="stylesheet" href="http://localhost/arcgis_js_api/library/3.9/3.9/js/esri/css/esri.css">  
  8.       
  9.     <script< span=""> type="text/javascript">  
  10.         dojoConfig = {  
  11.             parseOnLoad: true,  
  12.             packages: [{  
  13.                 name: 'bdlib',  
  14.                 location: this.location.pathname.replace(/\/[^/]+$/, "")+"/js/bdlib"  
  15.             }]  
  16.         };  
  17.       
  18.     <script< span=""> src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js">  
  19.     <script< span=""> src="js/jquery-1.8.3.js">  
  20.       
  21.   
  22.   
  23. <div< span=""> id="map">  
  24.     <div< span=""> class="base-map">  
  25.         <div< span=""> id="vec" class="base-map-switch base-map-switch-active" onclick="showMap('vec')">地图
  
  •         <div< span=""> id="img" class="base-map-switch base-map-switch-center"  onclick="showMap('img')">影像  
  •             <div< span=""> id="ano" class="base-map-ano">  
  •                 <input< span=""> id="chkAno" type="checkbox" name="chkAno" value="chkAno" onchange="anoCtrl()"/>标注  
  •               
  •           
  •       
  •   
  •   
  •   
posted @ 2022-07-13 10:28  devgis  阅读(637)  评论(0编辑  收藏  举报