Arcgis for flex 调用百度地图与Google地图

调用百度地图的ActionScripts脚本是用的网上一位“GIS大奔”的博客。
链接:http://www.gisall.com/html/72/124272-6284.html
百度地图API http://dev.baidu.com/wiki/static/index.htm
这调用百度地图和Google地图相差无几,只是坐标和几级的算法不一样的。这是GoogleMap 例子:
package com.esri.viewer
{
	import baidu.map.basetype.LngLat;
	import baidu.map.core.Map;
	
	import com.esri.ags.SpatialReference;
	import com.esri.ags.geometry.Extent;
	import com.esri.ags.geometry.MapPoint;
	import com.esri.ags.layers.TiledMapServiceLayer;
	import com.esri.ags.layers.supportClasses.LOD;
	import com.esri.ags.layers.supportClasses.TileInfo;
	
	import flash.net.URLRequest;
	
	//扩展TiledMapServiceLayer图层实现加载google地图
	public class GoogleMapLayer extends TiledMapServiceLayer
	{
		private var _tileInfo:TileInfo=new TileInfo();
		private var _baseURL:String="";//"http://192.168.10.190/testGD/_alllayers";
		public var mapStyle:String=""; 
		private var ints:int = 0;
		private var strUrl:String="";
		public function GoogleMapLayer()
		{
			super();
			buildTileInfo();
			setLoaded(true);
			
		}
		
		override public function get fullExtent():Extent
		{
			return new Extent(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787, new SpatialReference(2362));
		}
		
		override public function get initialExtent():Extent
		{
			return new Extent(12840697.0597065, 2671847.44992804, 13011984.1619692, 2869874.36172011, new SpatialReference(2362));
		}
		
		override public function get spatialReference():SpatialReference
		{
			return new SpatialReference(102113);
		}
		
		override public function get tileInfo():TileInfo
		{
			return _tileInfo;
		}
		
		//获取矢量地图
		override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
		{ 
			var s:String = "Galileo".substring(0, ((3 * x + y) % 8)); 
                        var url:String; 
                
                       //获取交通图地图             
                      if(mapStyle == "Vector")                 
                        {                 
                       url = "http://mt"+(col%4)+".google.cn/vt/lyrs=m@158000000&hl=zh-CN&gl=cn&" +                     
                        "x=" + col + "&" +                     
                        "y=" + row + "&" +                 
                        "z=" + level+ "&" +                 
                        "s=" + s;                 
                      }   
                
                   }
              private function padString(text:String, size:int, ch:String):String
		{
			while (text.length < size)
			{
				text = ch + text;
			}
			return text;
		}
		
		private function buildTileInfo():void
		{
			_tileInfo.height=256;
			_tileInfo.width=256;
			_tileInfo.origin=new MapPoint(-20037508.342787, 20037508.342787);
			_tileInfo.spatialReference=new SpatialReference(102113);
			_tileInfo.lods = [
				new LOD(1, 78271.5169639999, 295828763.795777),
				
				new LOD(2, 39135.7584820001, 147914381.897889),
				
				new LOD(3, 19567.8792409999, 73957190.948944),
				
				new LOD(4, 9783.93962049996, 36978595.474472),
				
				new LOD(5, 4891.96981024998, 18489297.737236),
				
				new LOD(6, 2445.98490512499, 9244648.868618), 
				new LOD(7, 1222.99245256249, 4622324.434309), 
				new LOD(8, 611.49622628138, 2311162.217155), 
				new LOD(9, 305.748113140558, 1155581.108577), 
				new LOD(10, 152.874056570411, 577790.554289), 
				new LOD(11, 76.4370282850732, 288895.277144), 
				new LOD(12, 38.2185141425366, 144447.638572), 
				new LOD(13, 19.1092570712683, 72223.819286), 
				new LOD(14, 9.55462853563415, 36111.909643), 
				new LOD(15, 4.77731426794937, 18055.954822),
				new LOD(16, 2.38865713397468, 9027.977411), 
				new LOD(17, 1.19432856685505, 4513.988705), 
				new LOD(18, 0.597164283559817, 2256.994353),
				new LOD(19, 0.298582141647617, 1128.497176)
			];
		}




                

两者相差的就是中间 重写 getTileURL 方法这一段。百度地图的这样调用。

                                
               //获取矢量地图
		override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
		{ 
                                 var zoom:int = level - 1;
				
				var offsetX:int = Math.pow(2, zoom) as int;
				
				var offsetY:int = offsetX - 1;
				
				var numX:int = col - offsetX;
				
				var numY:int = (-row) + offsetY;
				zoom = level + 1;
				
				var num:int = (col + row) % 8 + 1; 
				var url:String="";
				//获取矢量地图             
				if(mapStyle == "Vector")
				{                 
					url = "http://q" + num + ".baidu.com/it/u=x=" + numX + ";y=" + numY + ";z=" + zoom + ";v=014;type=web&fm=44";
				}                 					
			



                }



最后,我就加上GoogelMAP的地形图和卫星图+道路图的结合调用,百度的没有地形图,所以只写卫星图+道路的了。

Googlemap:

     地形图 url = "http://mt"+(col%4)+".google.cn/vt/lyrs=t@128,r@177000000&hl=zh-CN&gl=cn&" +                     
                        "x=" + col + "&" +                     
                        "y=" + row + "&" +                     
                        "z=" + level+ "&" +                     
                        "s=" + s;
   卫星图url = "http://mt"+(col%4)+".google.cn/vt/lyrs=s@106&hl=zh-CN&gl=cn&src=app&" +                            
                        "x=" + col + "&" +                     
                        "y=" + row + "&" +                     
                        "z=" + level+ "&" +                     
                        "s=" + s;
   道路图 url = "http://mt"+(col%4)+".google.cn/vt/imgtp=png32&lyrs=h@174000000&hl=zh-CN&gl=cn&src=app&" +                     
                        "x=" + col + "&" +                     
                        "y=" + row + "&" +                     
                        "z=" + level+ "&" +                     
                        "s=" + s;

Baidumap:

     卫星图 url = "http://q"+num+".baidu.com/it/u=x="+numX+";y="+numY+";z="+zoom+";v=009;type=sate&fm=46";

     道路图url = "http://q"+num+".baidu.com/it/u=x="+numX+";y="+numY+";z="+zoom+";v=014;type=trans&fm=47";

你可能感兴趣的:(Arcgis,Flex)