通常情况下我们直接使用ArcGISTiledMapServiceLayer来加载ArcGIS Server 发布的地图服务。但若我们需自定义一些功能的话,需扩展TiledMapServiceLayer来加载ArcGIS Server发布的切片地图。
下面我们一步一步来实现自定义TiledMapServiceLayer加载ArcGIS Server发布的切片:
首先查看需要加载的地图服务:http://x.x.x.x:8399/arcgis/rest/services/map/MapServer
内容大致如下:
Tile Info:
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;
}
}
}