博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcGIS Flex API读取自定义瓦片地图
阅读量:6217 次
发布时间:2019-06-21

本文共 12190 字,大约阅读时间需要 40 分钟。

博客分类:
 
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. }  
package com.esri.ags.samples{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.net.URLRequest;/** * PortlandTiledMapServiceLayer */public class PortlandTiledMapServiceLayer extends TiledMapServiceLayer{    //--------------------------------------------------------------------------    //    //  Constructor    //    //--------------------------------------------------------------------------    /**     * Creates a new PortlandTiledMapServiceLayer object.     */    public function PortlandTiledMapServiceLayer()    {        super();        buildTileInfo(); // to create our hardcoded tileInfo        setLoaded(true); // Map will only use loaded layers    }    //--------------------------------------------------------------------------    //    //  Variables    //    //--------------------------------------------------------------------------    private var _tileInfo:TileInfo = new TileInfo(); // see buildTileInfo()    private var _baseURL:String = "http://sampleserver1.arcgisonline.com/arcgiscache/Portland_Portland_ESRI_LandBase_AGO/Portland/_alllayers";    //--------------------------------------------------------------------------    //    //  Overridden properties    //      fullExtent()    //      initialExtent()    //      spatialReference()    //      tileInfo()    //      units()    //    //--------------------------------------------------------------------------    //----------------------------------    //  fullExtent    //  - required to calculate the tiles to use    //----------------------------------    override public function get fullExtent():Extent    {        return new Extent(-123.596895130725, 44.297575737946, -121.553757125519, 46.3683237161949, new SpatialReference(4326));    }    //----------------------------------    //  initialExtent    //  - needed if Map doesn't have an extent    //----------------------------------    override public function get initialExtent():Extent    {        return new Extent(-122.539, 45.500, -122.540, 45.501, new SpatialReference(4326));    }    //----------------------------------    //  spatialReference    //  - needed if Map doesn't have a spatialReference    //----------------------------------    override public function get spatialReference():SpatialReference    {        return new SpatialReference(4326);    }    //----------------------------------    //  tileInfo    //----------------------------------    override public function get tileInfo():TileInfo    {        return _tileInfo;    }    //----------------------------------    //  units    //  - needed if Map doesn't have it set    //----------------------------------    override public function get units():String    {        return "esriDecimalDegrees";    }    //--------------------------------------------------------------------------    //    //  Overridden methods    //      getTileURL(level:Number, row:Number, col:Number):URLRequest    //    //--------------------------------------------------------------------------    override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest    {        // Use virtual cache directory        // This assumes the cache's virtual directory is exposed, which allows you access        // to tile from the Web server via the public cache directory.        // Example of a URL for a tile retrieved from the virtual cache directory:        // http://serverx.esri.com/arcgiscache/dgaerials/Layers/_alllayers/L01/R0000051f/C000004e4.jpg        var url:String = _baseURL            + "/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 Methods    //    //--------------------------------------------------------------------------    private function buildTileInfo():void    {        _tileInfo.height = 512;        _tileInfo.width = 512;        _tileInfo.origin = new MapPoint(-180, 90);        _tileInfo.spatialReference = new SpatialReference(4326);        _tileInfo.lods =            [            new LOD(0, 0.351562499999999, 147748799.285417),            new LOD(1, 0.17578125, 73874399.6427087),            new LOD(2, 0.0878906250000001, 36937199.8213544),            new LOD(3, 0.0439453125, 18468599.9106772),            new LOD(4, 0.02197265625, 9234299.95533859),            new LOD(5, 0.010986328125, 4617149.97766929),            new LOD(6, 0.0054931640625, 2308574.98883465),            new LOD(7, 0.00274658203124999, 1154287.49441732),            new LOD(8, 0.001373291015625, 577143.747208662),            new LOD(9, 0.0006866455078125, 288571.873604331),            new LOD(10, 0.000343322753906249, 144285.936802165),            new LOD(11, 0.000171661376953125, 72142.9684010827),            new LOD(12, 0.0000858306884765626, 36071.4842005414),            new LOD(13, 0.0000429153442382813, 18035.7421002707),            new LOD(14, 0.0000214576721191406, 9017.87105013534),            new LOD(15, 0.0000107288360595703, 4508.93552506767)            ];    }    private function padString(text:String, size:int, ch:String):String    {        while (text.length < size)        {            text = ch + text;        }        return text;    }}}
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>  

转载地址:http://azlja.baihongyu.com/

你可能感兴趣的文章
如何在 OpenShift 上部署 NodeJS 应用
查看>>
公共云与私有云的成本计算比较
查看>>
一名黑客小鲜肉的“平凡之路”
查看>>
Linux Shell流程控制
查看>>
设计模块化数据中心
查看>>
一个“没节操”的黑客,2015年能赚多少钱?
查看>>
2016-2020年全球5G设备市场增长率预计达32%
查看>>
企业级云应用平台的实践和思考
查看>>
同一性是解锁物联网真正潜力的关键
查看>>
最新数据中心网络架构技术纵览
查看>>
你必须了解的基础的Linux网络命令
查看>>
中国电信将在5月12日发布物联网新政策
查看>>
路由器会泄露隐私信息? 黑客瞄准最前沿科技
查看>>
央视曝光网络消费陷阱 钓鱼网站变身成公众号骗取钱财
查看>>
CIA无法通过工厂固件攻破苹果的AirPort
查看>>
《测试驱动的嵌入式C语言开发》——1.1节为什么我们需要TDD
查看>>
IP RPR技术在地铁骨干网大规模应用 —— H3C承建香港地铁统一通信多业务承载网CDN...
查看>>
雅虎持有阿里530亿美元股份 但投资者估值却没那么高
查看>>
安防巨头大华半年股价翻倍的背后,AI起到了哪些作用
查看>>
漏洞报告平台的“漏洞” 70%网络安全事件都是人的问题
查看>>