Flexviewer兼容谷歌,百度,天地图等地图作为地图展示

 

   FlexViewer兼容各种地图,网上搜索了好多今天在这里总结下:只是展示三种,其余可去下载开发包(swc)

   地址:http://download.csdn.net/detail/dailiwei007/5028797

  1    谷歌的:

 

package
{
	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="";  
		private var _initialExtent:Extent;
		private var _wkid:int = 102113; 
		
		public var mapType:String="map"; 
		
		public function GoogleMapLayer(initialExtent:Extent=null)  
		{  
			super();  
			
			_initialExtent = initialExtent;
			
			buildTileInfo();  
			setLoaded(true);  
		}  
		
		override public function get fullExtent():Extent  
		{  
			return new Extent(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787, new SpatialReference(_wkid));
			//return new Extent(12879507.310507651, 4912113.73694047, 13087721.77555655, 5009188.7628626805, new SpatialReference(_wkid));
			
		}  
		
		override public function get initialExtent():Extent  
		{  
			if(_initialExtent)
				return _initialExtent;
			
			return fullExtent;
		}   
		
		override public function get spatialReference():SpatialReference  
		{  
			return new SpatialReference(_wkid);  
		}  
		
		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(mapType == "map")
			{
				url = "http://mt"+(col%4)+".google.cn/vt/lyrs=m@158000000&hl=zh-CN&gl=cn&" +
					"x=" + col + "&" +
					"y=" + row + "&" +
					"z=" + level+ "&" +
					"s=" + s;
			}
			else if(mapType == "image")//获取影像地图
			{
				url = "http://mt"+(col%4)+".google.cn/vt/lyrs=s@121&hl=zh-CN&gl=CN&src=api&" +
					"x=" + col + "&" +
					"y=" + row + "&" +
					"z=" + level+ "&" +
					"s=" + s;
			}
			else if(mapType == "poi")//获取道路等POI,和影像地图配合使用
			{
				url = "http://mt"+(col%4)+".google.cn/vt/imgtp=png32&lyrs=h@169000000&hl=zh-CN&gl=cn&" +
					"x=" + col + "&" +
					"y=" + row + "&" +
					"z=" + level+ "&" +
					"s=" + s;
			}
			else if(mapType == "topography"){
				url = "http://mt"+(col%4)+".google.cn/vt/lyrs=t@129,r@183000000&hl=zh-CN&gl=cn&src=app&" +
					"x=" + col + "&" +
					"y=" + row + "&" +
					"z=" + level+ "&" +
					"s=" + s;
			}
			
			return new URLRequest(url);  
		}  
		
		private function buildTileInfo():void 
		{  
			_tileInfo.height=256;  
			_tileInfo.width=256;   
			_tileInfo.origin=new MapPoint(-20037508.342787, 20037508.342787);  
			_tileInfo.spatialReference=new SpatialReference(_wkid);  
			_tileInfo.lods = [  
				new LOD(0, 156543.033928, 591657527.591555),   
				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)  
			];  
		}  
	}  
}

      2    百度的:


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;
	
	import flashx.textLayout.formats.Float; 
	
	public class BaiduTiledMapServiceLayer extends TiledMapServiceLayer   
	{ 
		//成员变量 
		private var _tileInfo:TileInfo = new TileInfo(); // see buildTileInfo() 
		private var _wkid:int = 102100;//102100; 
		private var cornerCoordinate:Number = 20037508.3427892; 
		public var mapType:String = "map"; 
		private var _initialExtent:Extent;

		public function BaiduTiledMapServiceLayer() 
		{ 
			super(); 
			buildTileInfo(); // to create our hardcoded tileInfo 
			setLoaded(true); // Map will only use loaded layers 
		} 
		
		//---------------------------------- 
		//  全屏范围 
		//---------------------------------- 
		override public function get fullExtent():Extent 
		{ 
			return new Extent(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate, new SpatialReference(_wkid)); 
		} 
		//---------------------------------- 
		//  初始化范围 
		//---------------------------------- 
		override public function get initialExtent():Extent 
		{ 
			if (_initialExtent)
				return _initialExtent;
			
			return fullExtent;
		} 
		//---------------------------------- 
		//  空间参考系 
		//---------------------------------- 
		override public function get spatialReference():SpatialReference 
		{ 
			return new SpatialReference(_wkid); 
		} 
		//---------------------------------- 
		//  tileInfo 
		//---------------------------------- 
		override public function get tileInfo():TileInfo 
		{ 
			return _tileInfo; 
		} 
		//-------------------------------------------------------------------------- 
		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 = null; 
			if (mapType == "map") 
			{  
				url = "http://q"+num+".baidu.com/it/u=x="+numX+";y="+ numY + ";z=" + zoom + ";v=013;type=web&fm=44"; 
			} 
			else if (mapType == "image") 
			{  
				url = "http://q"+num+".baidu.com/it/u=x="+numX+";y="+numY+";z="+zoom+";v=009;type=sate&fm=46"; 
			} 
			else if (mapType == "poi") 
			{  
				url = "http://q"+num+".baidu.com/it/u=x="+numX+";y="+numY+";z="+zoom+";v=013;type=trans&fm=47"; 
			} 
			return new URLRequest(url); 
		} 
		//-------------------------------------------------------------------------- 
		// 
		//  自定义方法,定义地图缩放等级 
		// 
		//-------------------------------------------------------------------------- 
		private function buildTileInfo():void 
		{ 
			_tileInfo.height=256; 
			_tileInfo.width=256; 
			_tileInfo.origin=new MapPoint(-cornerCoordinate, cornerCoordinate); 
			_tileInfo.spatialReference=new SpatialReference(_wkid); 
			_tileInfo.lods = [ 
				new LOD(0, 156543.033928, 591657527.591555), 
				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) 
			]; 
		} 
	} 

       3    天地图的:

package
{
	import com.esri.ags.SpatialReference;
	import com.esri.ags.geometry.Extent;
	import com.esri.ags.geometry.MapPoint;
	import com.esri.ags.layers.supportClasses.LOD;
	import com.esri.ags.layers.supportClasses.TileInfo;
	import com.esri.ags.layers.TiledMapServiceLayer;
	
	import flash.geom.Point;
	import flash.net.URLRequest;
	
	/**
	 * SXGeoTileLayer 
	 */
	public class TianDiTuTiledMapServiceLayer3 extends TiledMapServiceLayer
	{
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		/**
		 * Creates a new PortlandTiledMapServiceLayer object.
		 */
		private var _initialExtent:Extent;

		private var _hosts:Array = new Array("tile0", "tile1", "tile2", "tile3", "tile4", "tile5", "tile6", "tile7");
		public function TianDiTuTiledMapServiceLayer3()
		{
			super();
			
			buildTileInfo(); // to create our hardcoded tileInfo 
			
			setLoaded(true); // Map will only use loaded layers
		}
		
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		
		private var  wkid:int = 4326;//102113
		private var _tileInfo:TileInfo = new TileInfo();  // see buildTileInfo() 
		private var _url:String = new String();
 
		public var mapType:String="map";

		override public function get fullExtent():Extent
		{
			return new Extent(-180, -90, 180, 90, new SpatialReference(wkid));
		}
		
		//----------------------------------
		//  initialExtent
		//  - needed if Map doesn't have an extent
		//----------------------------------
		
		override public function get initialExtent():Extent
		{
			if (_initialExtent)
				return _initialExtent;
			
			return fullExtent;
		}
		
		//----------------------------------
		//  spatialReference
		//  - needed if Map doesn't have a spatialReference
		//----------------------------------
		
		override public function get spatialReference():SpatialReference
		{
			return new SpatialReference(wkid);
		}
		
		//----------------------------------
		//  tileInfo
		//----------------------------------
		
		override public function get tileInfo():TileInfo
		{   
			return _tileInfo;
		}
		
		//----------------------------------
		//  units
		//  - needed if Map doesn't have it set
		//----------------------------------
	 
 
		override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
		{
			var index:int = Math.abs(col%7);
			var host:String = _hosts[index];
			var url:String = "";
			if( mapType == "map")
			{
				if (level < 10)
				{  
					url="http://"+host+".tianditu.com/DataServer?T=A0512_EMap&X="+col+"&Y="+ row+"&L="+ (level+1);
				}
				else if (level < 12)
				{
					url="http://"+host+".tianditu.com/DataServer?T=B0627_EMap1112&X="+col+"&Y="+ row+"&L="+ (level+1);
				}
				else
				{
					url="http://"+host+".tianditu.com/DataServer?T=siwei0608&X="+col+"&Y="+ row+"&L="+(level+1);
				}
			}
			if (mapType == "poi")
			{
				if (level < 10)
				{
					url="http://"+host+".tianditu.com/DataServer?T=A0610_ImgAnno&X="+col+"&Y="+ row+"&L="+(level+1)+"&INDATE=9999-01-01%2000%3A00%3A00";
				}else if(level ==10||level==11)
				{ 
					url="http://"+host+".tianditu.com/DataServer?T=B0530_eImgAnno&X="+col+"&Y="+ row+"&L="+(level+1)+"&INDATE=9999-01-01%2000%3A00%3A00";
				}else if(level > 11)
				{ 
					url="http://"+host+".tianditu.com/DataServer?T=tdt_tran_dong_13_18_dyd&X="+col+"&Y="+ row+"&L="+(level+1)+"&INDATE=9999-01-01%2000%3A00%3A00";

				}
			}
			if(mapType == "dem"){
				if (level <= 11)
				{
					url="http://"+host+".tianditu.com/DataServer?T=DemYuXun&X="+col+"&Y="+ row+"&L="+(level+1)+"&INDATE=9999-01-01%2000%3A00%3A00";
				}else if(level ==12)
				{ 
					url="http://"+host+".tianditu.com/DataServer?T=DemYunXun_E13&X="+col+"&Y="+ row+"&L="+(level+1)+"&INDATE=9999-01-01%2000%3A00%3A00";
				}else if(level > 12)
				{ 
					url="http://"+host+".tianditu.com/DataServer?T=DemYunXun_E14&X="+col+"&Y="+ row+"&L="+(level+1)+"&INDATE=9999-01-01%2000%3A00%3A00";
					
				}
			
			}
			if (mapType == "image")
			{
				if (level < 10)
				{
					url="http://"+host+".tianditu.com/DataServer?T=tdt_vip_img_2_10_120627&X="+col+"&Y="+ row+"&L="+(level+1)+"&INDATE=9999-01-01%2000%3A00%3A00";
				}
				else if (level == 10)
				{
					url="http://"+host+".tianditu.com/DataServer?T=e11&X="+col+"&Y="+ row+"&L="+(level+1);
				}
				else if (level == 11)
				{
					url="http://"+host+".tianditu.com/DataServer?T=e12&X="+col+"&Y="+ row+"&L="+(level+1);
				}
				else if (level == 12)
				{
					url="http://"+host+".tianditu.com/DataServer?T=e13&X="+col+"&Y="+ row+"&L="+(level+1);
				}
				else if (level == 13)
				{
					url="http://"+host+".tianditu.com/DataServer?T=eastdawnall&X="+col+"&Y="+ row+"&L="+(level+1);
				}
				else
				{
					url="http://"+host+".tianditu.com/DataServer?T=sbsm1518&X="+col+"&Y="+ row+"&L="+(level+1);
				}
			}
			return new URLRequest(url) ;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Private Methods
		//
		//--------------------------------------------------------------------------
		
		private function buildTileInfo():void
		{
			_tileInfo.height = 256;
			_tileInfo.width = 256;
			_tileInfo.origin = new MapPoint(-180, 90);
			_tileInfo.spatialReference = new SpatialReference(wkid);
			_tileInfo.lods = [    
				new LOD(0, 0.703125, 2.95498e+008), 
				new LOD(1, 0.351563,1.47749e+008),
				new LOD(2,0.175781,7.38744e+007),
				new LOD(3,0.0878906,3.69372e+007),
				new LOD(4,0.0439453,1.84686e+007),
				new LOD(5,0.0219727,9.2343e+006),
				new LOD(6,0.0109863,4.61715e+006),
				new LOD(7,0.00549316,2.30857e+006),
				new LOD(8,0.00274658,1.15429e+006),
				new LOD(9,0.00137329,577144),
				new LOD(10,0.000686646,288572),
				new LOD(11,0.000343323,144286),
				new LOD(12,0.000171661,72143),
				new LOD(13,8.58307e-005,36071.5),
				new LOD(14,4.29153e-005,18035.7),
				new LOD(15,2.14577e-005,9017.87),
				new LOD(16,1.07289e-005,4508.9),
				new LOD(17,5.36445e-006,2254.47)
			];
		}
		
		private function padString(text:String, size:int, ch:String):String
		{
			while (text.length < size)
			{
				text = ch + text;
			}
			return text;
		}
		public function set url(val:String):void
		{
			this._url = val;
		}
	}
}


    4  结束,谢谢!!!

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页