扩展TiledMapServiceLayer,加载ArcGIS Server发布的切片地图

通常情况下我们直接使用ArcGISTiledMapServiceLayer来加载ArcGIS Server 发布的地图服务。但若我们需自定义一些功能的话,需扩展TiledMapServiceLayer来加载ArcGIS Server发布的切片地图。

下面我们一步一步来实现自定义TiledMapServiceLayer加载ArcGIS Server发布的切片:

首先查看需要加载的地图服务:http://x.x.x.x:8399/arcgis/rest/services/map/MapServer

内容大致如下:

Tile Info:

  • Height: 256
  • Width: 256
  • DPI: 96
  • Levels of Detail: (# Levels 10)
    • Level ID: 0 [ Start Tile, End Tile ]
      • Resolution: 0.0023794610058302797
        Scale: 1000000.0
    • Level ID: 1 [ Start Tile, End Tile ]
      • Resolution: 0.0011897305029151398
        Scale: 500000.0
    • Level ID: 2 [ Start Tile, End Tile ]
      • Resolution: 5.948652514575699E-4
        Scale: 250000.0
    • Level ID: 3 [ Start Tile, End Tile ]
      • Resolution: 2.9743262572878496E-4
        Scale: 125000.0
    • Level ID: 4 [ Start Tile, End Tile ]
      • Resolution: 1.522855043731379E-4
        Scale: 64000.0
    • Level ID: 5 [ Start Tile, End Tile ]
      • Resolution: 7.614275218656895E-5
        Scale: 32000.0
    • Level ID: 6 [ Start Tile, End Tile ]
      • Resolution: 3.8071376093284474E-5
        Scale: 16000.0
    • Level ID: 7 [ Start Tile, End Tile ]
      • Resolution: 1.9035688046642237E-5
        Scale: 8000.0
    • Level ID: 8 [ Start Tile, End Tile ]
      • Resolution: 9.517844023321119E-6
        Scale: 4000.0
    • Level ID: 9 [ Start Tile, End Tile ]
      • Resolution: 4.758922011660559E-6
        Scale: 2000.0
  • Format: PNG24
  • Compression Quality: 0
  • Origin: X: -400.0
                 Y: 400.0
  • Spatial Reference: 4326

Initial Extent:

XMin: 110

YMin: 20

XMax: 112

YMax: 30

Spatial Reference: 4326

Full Extent:

XMin: 110

YMin: 20

XMax: 112

YMax: 30

Spatial Reference: 4326

其中

      切片大小

      切片原点

      切片格式

      每一级切片的分辨率、比例尺

      地图初始化范围

      地图范围

对扩展TiledMapServiceLayer非常重要。

 

下面我们来扩展TiledMapServiceLayer

package com.css.conponents
{
 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;

 public class MyMapServiceLayer extends TiledMapServiceLayer
 {
  public function MyMapServiceLayer()
  {
   super();   
   buildTileInfo(); // to create our hardcoded tileInfo   
   setLoaded(true); // Map will only use loaded layers
  }
  
  private var _tileInfo:TileInfo = new TileInfo(); // see buildTileInfo()
  private var _baseURL:String = "http://x.x.x.x:8399/arcgis/server/arcgiscache/map/Layers/_alllayers";
    // 对应 Initial Extent: 
  override public function get fullExtent():Extent
  {
   return new Extent(110, 20, 112, 30, new SpatialReference(4326));
  }
  // 对应 Full Extent:

  override public function get initialExtent():Extent
  {
   return new Extent(110, 20, 112, 30, new SpatialReference(4326));
  }
  
  override public function get spatialReference():SpatialReference
  {
   return new SpatialReference(4326);
  }
    
  override public function get tileInfo():TileInfo
  {
   return _tileInfo;
  }
  override protected function getTileURL(level:Number, row:Number, col:Number):URLRequest
  {
    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 function buildTileInfo():void
  {

  // 对应   Tile Info:height /width :
   _tileInfo.height = 256;
   _tileInfo.width = 256;

  // 对应 Tile Info:Origin :
   _tileInfo.origin = new MapPoint(-400, 400);
   _tileInfo.spatialReference = new SpatialReference(4326);

  // 对应 Tile Info: Levels of Detail:
   _tileInfo.lods =
    [

     new LOD(0, 0.0023794610058302797, 1000000.0),
           ...

     new LOD(9, 4.758922011660559E-6,2000)
    ];
  }
  
  private function padString(text:String, size:int, ch:String):String
  {
   while (text.length < size)
   {
    text = ch + text;
   }
   return text;
  }
 }
 
}

 

你可能感兴趣的:(ArcGIS,GIS,WEB,GIS,Flex)