现在的位置: 首页 > 综合 > 正文

Arcgis for Flex 笔记

2013年12月12日 ⁄ 综合 ⁄ 共 5593字 ⁄ 字号 评论关闭

读取自定义切片

public byte[] getServiceConf(string ServiceName)
        {
            string ConfDir = MapPath + "\\" + ServiceName + "\\Layers\\conf.xml";
            FileStream conf = new FileStream(ConfDir, FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[conf.Length];
            conf.Read(buffer, 0, (int)conf.Length);
            return buffer;
        }
        public byte[] getServiceCdi(string ServiceName)
        {
            string ConfDir = MapPath + "\\" + ServiceName + "\\Layers\\conf.cdi";
            FileStream conf = new FileStream(ConfDir, FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[conf.Length];
            conf.Read(buffer, 0, (int)conf.Length);
            return buffer;
        }
        public byte[] getTile(string ServiceName, int level, int row, int col)
        {
            int size = 128;
            byte[] result = null;
            FileStream isBundle = null;
            FileStream isBundlx = null;
            try
            {
                string bundlesDir = MapPath + "\\" + ServiceName + "\\Layers\\_alllayers";
                string l = "0" + level;
                int lLength = l.Length;
                if (lLength > 2)
                {
                    l = l.Substring(lLength - 2);
                }
                l = "L" + l;

                int rGroup = size * (row / size);
                string r = "000" + rGroup.ToString("X");
                int rLength = r.Length;
                if (rLength > 4)
                {
                    r = r.Substring(rLength - 4);
                }
                r = "R" + r;

                int cGroup = size * (col / size);
                string c = "000" + cGroup.ToString("X");
                int cLength = c.Length;
                if (cLength > 4)
                {
                    c = c.Substring(cLength - 4);
                }
                c = "C" + c;

                string bundleBase = bundlesDir + "//" + l + "//" + r + c;
                string bundlxFileName = bundleBase + ".bundlx";
                string bundleFileName = bundleBase + ".bundle";

                int index = size * (col - cGroup) + (row - rGroup);
                isBundlx = new FileStream(bundlxFileName, FileMode.Open, FileAccess.Read);
                isBundlx.Seek(16 + 5 * index, SeekOrigin.Begin);
                byte[] buffer = new byte[5];
                isBundlx.Read(buffer, 0, 5);
                long offset = (long)(buffer[0] & 0xff) + (long)(buffer[1] & 0xff)
                        * 256 + (long)(buffer[2] & 0xff) * 65536
                        + (long)(buffer[3] & 0xff) * 16777216
                        + (long)(buffer[4] & 0xff) * 4294967296L;

                isBundle = new FileStream(bundleFileName, FileMode.Open, FileAccess.Read);
                isBundle.Seek(offset, SeekOrigin.Begin);
                byte[] lengthBytes = new byte[4];
                isBundle.Read(lengthBytes, 0, 4);
                int length = (int)(lengthBytes[0] & 0xff)
                        + (int)(lengthBytes[1] & 0xff) * 256
                        + (int)(lengthBytes[2] & 0xff) * 65536
                        + (int)(lengthBytes[3] & 0xff) * 16777216;
                result = new byte[length];
                isBundle.Read(result, 0, length);
            }
            catch (Exception ex)
            {
                return NoImage;
            }
            finally
            {
                if (isBundle != null)
                {
                    isBundle.Close();
                    isBundlx.Close();
                }
            }
            return result;
        }

package overrides
{
	import com.esri.ags.SpatialReference;
	import com.esri.ags.Units;
	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.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.controls.Alert;
	import mx.controls.Image;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	public class LocalTiledMapServiceLayer extends TiledMapServiceLayer
	{
		private var _fullExtent:Extent;
		private var _initialExtent:Extent;
		private var _spatialReference:SpatialReference;
		private var _tileInfo:TileInfo;
		private var _tileServers:Array;
		private var _tileServersChanged:Boolean=true;
		private var _url:String="";
		public function RadioTiledMapServiceLayer(url:String=null)
		{
			super();
			this._fullExtent = new Extent(-180,-90, 180, 90, new SpatialReference(4326));
			this._initialExtent = new Extent(-180,-90, 180, 90, new SpatialReference(4326));
			this._tileInfo = new TileInfo();
			this.Url=url;			
			return;
		}
		public function get Url():String
		{
			return _url;
		}
		public function set Url(value:String):void
		{
			if(this.Url!=value)
			{
				if (value)
				{
					this._url=value;
					var mUrlRequest:URLRequest=new URLRequest(value+"&action=info");
					var load:URLLoader=new URLLoader();
					load.addEventListener(Event.COMPLETE,complete);
					load.addEventListener(IOErrorEvent.IO_ERROR,onError);
					load.load(mUrlRequest);
					
					
				}
			}
		}
		private function onError(event:IOErrorEvent):void
		{
			Alert.show(event.text);
		}
		private function completecdi(event:Event):void
		{
			var cdi:XML=new XML(event.target.data);
			var XMin:Number=Number(cdi.XMin);
			var XMax:Number=Number(cdi.XMax);
			var YMin:Number=Number(cdi.YMin);
			var YMax:Number=Number(cdi.YMax);
			this._fullExtent = new Extent(XMin,YMin, XMax, YMax,this.spatialReference);
			this._initialExtent = new Extent(XMin,YMin, XMax, YMax,this.spatialReference);
			setLoaded(true);
		}
		private function complete(event:Event):void
		{
			var conf:XML=new XML(event.target.data);
			var CacheInfo:XMLList=conf..TileCacheInfo;
			_tileInfo.lods=new Array();
			_tileInfo.dpi=CacheInfo.DPI;
			_tileInfo.height=CacheInfo.TileRows;
			_tileInfo.width=CacheInfo.TileCols;
			_tileInfo.origin=new MapPoint(CacheInfo.TileOrigin.X, CacheInfo.TileOrigin.Y);
			
			var LodInfos:XMLList=CacheInfo.LODInfos.LODInfo;
			for(var i:int=0;i<LodInfos.length();i++)
			{
				var LevelID:int=LodInfos[i].LevelID;
				var Scale:Number=LodInfos[i].Scale;
				var Resolution:Number=LodInfos[i].Resolution;
				_tileInfo.lods.push(new LOD(LevelID,Resolution,Scale));
			}
			this._spatialReference = new SpatialReference(CacheInfo.SpatialReference.WKID);
			
			///获取cdi信息,即地图范围信息
			var mUrlRequestCdi:URLRequest=new URLRequest(this.Url+"&action=cdi");
			var loadcdi:URLLoader=new URLLoader();
			loadcdi.addEventListener(Event.COMPLETE,completecdi);
			loadcdi.addEventListener(IOErrorEvent.IO_ERROR,onError);
			loadcdi.load(mUrlRequestCdi);
		}
		override public function get fullExtent() : Extent
		{
			return this._fullExtent;
		}// end function
		
		override public function get initialExtent() : Extent
		{
			return this._initialExtent;
		}// end function
		
		override public function get spatialReference() : SpatialReference
		{
			return this._spatialReference;
		}// end function
		
		override public function get tileInfo() : TileInfo
		{
			return this._tileInfo;
		}// end function
		
		override public function get units() : String
		{
			return Units.METERS;
		}// end function
		
		override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
		{
			var _baseURL:String=Url;
			var url:String=_baseURL+"&action=img&l=" + level.toString() + "&r=" + row.toString() + "&c="+col.toString(); 
			return new URLRequest(url);
		}
	}
}

抱歉!评论已关闭.