Flex读取离线地图CacheMap

package com
{
	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.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class CacheMap extends TiledMapServiceLayer
	{
		public var _baseURL:String="";
		public var _fullextent:String="";
		public var _initextent:String="";
		[Bindable]
		private var xmlList:XMLList;

		public function CacheMap()
		{
			super();
		}

		private function iniParam():void
		{
			buildTileInfo();
			setLoaded(true);
		}
		private var _tileInfo:TileInfo=new TileInfo();

		/*读取conf.xml文件*/
		[Bindable]
		private var datas:XML=new XML();
		private var tileCols:Number;
		private var tileRows:Number;
		private var tileOriginX:Number;
		private var tileOriginY:Number;
		private var lodInfo:Array=[];

		public function getXml():void
		{
			var url:URLRequest=new URLRequest(_baseURL + "/conf.xml");
			var loader:URLLoader=new URLLoader();
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(url);
		}

		private function onComplete(event:Event):void
		{
			var result:URLLoader=URLLoader(event.target);
			datas=XML(result.data);
			tileCols=Number(datas.TileCacheInfo.TileCols);
			tileRows=Number(datas.TileCacheInfo.TileRows);
			tileOriginX=Number(datas.TileCacheInfo.TileOrigin.X);
			tileOriginY=Number(datas.TileCacheInfo.TileOrigin.Y);
			var lodInfoArr:XMLList=datas.TileCacheInfo.LODInfos.LODInfo;
			_tileInfo.lods=[];
			for (var i:int=0; i < lodInfoArr.length(); i++)
			{
				var xmlObj:XML=lodInfoArr[i];
				var lodObj:LOD=new LOD(xmlObj.LevelID, xmlObj.Resolution, xmlObj.Scale);
				_tileInfo.lods.push(lodObj);
			}
			iniParam();
		}






		override public function get fullExtent():Extent
		{
			var fullExtentArr:Array=_fullextent.split(",");
			return new Extent(Number(fullExtentArr[0]), Number(fullExtentArr[1]), Number(fullExtentArr[2]), Number(fullExtentArr[3]), new SpatialReference(4326));
		}



		override public function get initialExtent():Extent
		{
			var initExtentArr:Array=_initextent.split(",");
			return new Extent(Number(initExtentArr[0]), Number(initExtentArr[1]), Number(initExtentArr[2]), Number(initExtentArr[3]), new SpatialReference(4326));
		}


		override public function get spatialReference():SpatialReference
		{
			return new SpatialReference(4326);
		}



		override public function get tileInfo():TileInfo
		{
			return _tileInfo;
		}



		/*override public function get units():String
		{
			return "esriDecimalDegrees";
		}*/



		override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
		{
			var url:String=_baseURL + "/_alllayers" + "/L" + padString(String(level), 2, "0") + "/R" + padString(row.toString(16), 8, "0") + "/C" + padString(col.toString(16), 8, "0") + ".png";
			return new URLRequest(url);
		}


		private function buildTileInfo():void
		{
			_tileInfo.height=tileCols;
			_tileInfo.width=tileRows;
			_tileInfo.origin=new MapPoint(tileOriginX, tileOriginY);
			_tileInfo.spatialReference=new SpatialReference(4326);
		}

		private function padString(text:String, size:int, ch:String):String
		{
			while (text.length < size)
			{
				text=ch + text;
			}
			return text;
		}
	}

}

你可能感兴趣的:(Flex读取离线地图CacheMap)