少尉

嗯。

 

ArcGIS Flex API读取自定义瓦片地图

PortlandTiledMapServiceLayer.as
Java代码 复制代码 收藏代码
  1. package com.esri.ags.samples   
  2. {   
  3.   
  4. import com.esri.ags.SpatialReference;   
  5. import com.esri.ags.geometry.Extent;   
  6. import com.esri.ags.geometry.MapPoint;   
  7. import com.esri.ags.layers.supportClasses.LOD;   
  8. import com.esri.ags.layers.supportClasses.TileInfo;   
  9. import com.esri.ags.layers.TiledMapServiceLayer;   
  10.   
  11. import flash.net.URLRequest;   
  12.   
  13. /**  
  14.  * PortlandTiledMapServiceLayer  
  15.  */  
  16. public class PortlandTiledMapServiceLayer extends TiledMapServiceLayer   
  17. {   
  18.     //--------------------------------------------------------------------------   
  19.     //   
  20.     //  Constructor   
  21.     //   
  22.     //--------------------------------------------------------------------------   
  23.   
  24.     /**  
  25.      * Creates a new PortlandTiledMapServiceLayer object.  
  26.      */  
  27.     public function PortlandTiledMapServiceLayer()   
  28.     {   
  29.         super();   
  30.   
  31.         buildTileInfo(); // to create our hardcoded tileInfo   
  32.   
  33.         setLoaded(true); // Map will only use loaded layers   
  34.     }   
  35.   
  36.     //--------------------------------------------------------------------------   
  37.     //   
  38.     //  Variables   
  39.     //   
  40.     //--------------------------------------------------------------------------   
  41.   
  42.     private var _tileInfo:TileInfo = new TileInfo(); // see buildTileInfo()   
  43.     private var _baseURL:String = "http://sampleserver1.arcgisonline.com/arcgiscache/Portland_Portland_ESRI_LandBase_AGO/Portland/_alllayers";   
  44.   
  45.     //--------------------------------------------------------------------------   
  46.     //   
  47.     //  Overridden properties   
  48.     //      fullExtent()   
  49.     //      initialExtent()   
  50.     //      spatialReference()   
  51.     //      tileInfo()   
  52.     //      units()   
  53.     //   
  54.     //--------------------------------------------------------------------------   
  55.   
  56.   
  57.     //----------------------------------   
  58.     //  fullExtent   
  59.     //  - required to calculate the tiles to use   
  60.     //----------------------------------   
  61.   
  62.     override public function get fullExtent():Extent   
  63.     {   
  64.         return new Extent(-123.59689513072544.297575737946, -121.55375712551946.3683237161949new SpatialReference(4326));   
  65.     }   
  66.   
  67.     //----------------------------------   
  68.     //  initialExtent   
  69.     //  - needed if Map doesn't have an extent   
  70.     //----------------------------------   
  71.   
  72.     override public function get initialExtent():Extent   
  73.     {   
  74.         return new Extent(-122.53945.500, -122.54045.501new SpatialReference(4326));   
  75.     }   
  76.   
  77.     //----------------------------------   
  78.     //  spatialReference   
  79.     //  - needed if Map doesn't have a spatialReference   
  80.     //----------------------------------   
  81.   
  82.     override public function get spatialReference():SpatialReference   
  83.     {   
  84.         return new SpatialReference(4326);   
  85.     }   
  86.   
  87.     //----------------------------------   
  88.     //  tileInfo   
  89.     //----------------------------------   
  90.   
  91.     override public function get tileInfo():TileInfo   
  92.     {   
  93.         return _tileInfo;   
  94.     }   
  95.   
  96.     //----------------------------------   
  97.     //  units   
  98.     //  - needed if Map doesn't have it set   
  99.     //----------------------------------   
  100.   
  101.     override public function get units():String   
  102.     {   
  103.         return "esriDecimalDegrees";   
  104.     }   
  105.   
  106.     //--------------------------------------------------------------------------   
  107.     //   
  108.     //  Overridden methods   
  109.     //      getTileURL(level:Number, row:Number, col:Number):URLRequest   
  110.     //   
  111.     //--------------------------------------------------------------------------   
  112.   
  113.     override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest   
  114.     {   
  115.         // Use virtual cache directory   
  116.         // This assumes the cache's virtual directory is exposed, which allows you access   
  117.         // to tile from the Web server via the public cache directory.   
  118.         // Example of a URL for a tile retrieved from the virtual cache directory:   
  119.         // http://serverx.esri.com/arcgiscache/dgaerials/Layers/_alllayers/L01/R0000051f/C000004e4.jpg   
  120.         var url:String = _baseURL   
  121.             + "/L" + padString(String(level), 2"0")   
  122.             + "/R" + padString(row.toString(16), 8"0")   
  123.             + "/C" + padString(col.toString(16), 8"0") + ".png";   
  124.         return new URLRequest(url);   
  125.     }   
  126.   
  127.     //--------------------------------------------------------------------------   
  128.     //   
  129.     //  Private Methods   
  130.     //   
  131.     //--------------------------------------------------------------------------   
  132.   
  133.     private function buildTileInfo():void  
  134.     {   
  135.         _tileInfo.height = 512;   
  136.         _tileInfo.width = 512;   
  137.         _tileInfo.origin = new MapPoint(-18090);   
  138.         _tileInfo.spatialReference = new SpatialReference(4326);   
  139.         _tileInfo.lods =   
  140.             [   
  141.             new LOD(00.351562499999999147748799.285417),   
  142.             new LOD(10.1757812573874399.6427087),   
  143.             new LOD(20.087890625000000136937199.8213544),   
  144.             new LOD(30.043945312518468599.9106772),   
  145.             new LOD(40.021972656259234299.95533859),   
  146.             new LOD(50.0109863281254617149.97766929),   
  147.             new LOD(60.00549316406252308574.98883465),   
  148.             new LOD(70.002746582031249991154287.49441732),   
  149.             new LOD(80.001373291015625577143.747208662),   
  150.             new LOD(90.0006866455078125288571.873604331),   
  151.             new LOD(100.000343322753906249144285.936802165),   
  152.             new LOD(110.00017166137695312572142.9684010827),   
  153.             new LOD(120.000085830688476562636071.4842005414),   
  154.             new LOD(130.000042915344238281318035.7421002707),   
  155.             new LOD(140.00002145767211914069017.87105013534),   
  156.             new LOD(150.00001072883605957034508.93552506767)   
  157.             ];   
  158.     }   
  159.   
  160.     private function padString(text:String, size:int, ch:String):String   
  161.     {   
  162.         while (text.length < size)   
  163.         {   
  164.             text = ch + text;   
  165.         }   
  166.         return text;   
  167.     }   
  168. }   
  169.   
  170. }  


customtiled.mxml
Java代码 复制代码 收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  
  3.                xmlns:s="library://ns.adobe.com/flex/spark"  
  4.                xmlns:mx="library://ns.adobe.com/flex/mx"  
  5.                xmlns:esri="http://www.esri.com/2008/ags"  
  6.                xmlns:samples="com.esri.ags.samples.*"  
  7.                pageTitle="Extending TiledMapServiceLayer in Flex API">   
  8.     <!--   
  9.          @@includeFiles com/esri/ags/samples/PortlandTiledMapServiceLayer.as   
  10.   
  11.          This sample shows how tiles can be used without the REST endpoint.   
  12.   
  13.          The ArcGIS API for Flex allows for extending the API   
  14.          to access layer types not included as part of the API.   
  15.          In this example, tiled layers (TiledMapServiceLayer) is extended   
  16.          to access tiles created in 9.2 or above and made accessible   
  17.          in the standard virtual directory.   
  18.   
  19.          Steps involved:   
  20.          1. Creating new ActionScript class that extends TiledMapServiceLayer.   
  21.          2. Hardcoding some of the configuration settings:   
  22.          fullExtent, initialExtent, spatialReference, tileInfo, and units.   
  23.          3. Overriding the protected function getTileURL() to obtain the appropriate   
  24.          tiles and place them accurately on the map.   
  25.          4. Using the extended class with MXML or ActionScript :)   
  26.     -->   
  27.   
  28.     <esri:Map id="myMap">   
  29.         <samples:PortlandTiledMapServiceLayer id="virtualTiles" fadeInFrameCount="12"/>   
  30.     </esri:Map>   
  31.   
  32.     <s:Label width="85%"  
  33.              backgroundColor="0xFFFF00"  
  34.              color="0x000000"  
  35.              fontSize="14"  
  36.              fontWeight="bold"  
  37.              horizontalCenter="0"  
  38.              paddingBottom="10"  
  39.              paddingLeft="10"  
  40.              paddingRight="10"  
  41.              paddingTop="10"  
  42.              text="By extending TiledMapServiceLayer, this application can access tiles from an ArcGIS 9.2 (or above) virtual directory.  This specific service is in the {virtualTiles.spatialReference.wkid} spatialReference and has {virtualTiles.tileInfo.lods.length} scale levels."/>   
  43. </s:Application>  

posted on 2012-06-18 22:35  moonvan  阅读(2275)  评论(0编辑  收藏  举报

导航