继承 TiledMapServiceLayer 编写SXGeoTileLayer 类
package ext
{
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 com.esri.ags.layers.TiledMapServiceLayer;
import flash.geom.Point;
import flash.net.URLRequest;
/**
* SXGeoTileLayer 吉奥的地图服务
*/
public class SXGeoTileLayer extends TiledMapServiceLayer
{
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Creates a new PortlandTiledMapServiceLayer object.
*/
public function SXGeoTileLayer()
{
super();
buildTileInfo(); // to create our hardcoded tileInfo
setLoaded(true); // Map will only use loaded layers
}
//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------
private var wkid:int = 4326;
private var _tileInfo:TileInfo = new TileInfo(); // see buildTileInfo()
private var _url:String = new String();
//private var _wmsLayer:String = new String();
//--------------------------------------------------------------------------
//
// Overridden properties
// fullExtent()
// initialExtent()
// spatialReference()
// tileInfo()
// units()
//
//--------------------------------------------------------------------------
//----------------------------------
// fullExtent
// - required to calculate the tiles to use
//----------------------------------
override public function get fullExtent():Extent
{
return new Extent(-180,-90,180,90,new SpatialReference(4326));
//return new Extent(65.94,18.84,137.74,62.85,new SpatialReference(4326));
}
//----------------------------------
// initialExtent
// - needed if Map doesn't have an extent
//----------------------------------
override public function get initialExtent():Extent
{
return new Extent(-124.731422,24.955967,-66.969849,49.371735,new SpatialReference(4326));
//return new Extent(112.48,47.77,112.60,47.97,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,col:Number):URLRequest
{
var url:String ;
url = _url + "&X=" + col.toString() + "&Y=" + row.toString()+ "&L="+ level.toString();
return new URLRequest(url) ;
}
//--------------------------------------------------------------------------
//
// Private Methods
//
//--------------------------------------------------------------------------
private function buildTileInfo():void
{
_tileInfo.height = 256;
_tileInfo.width = 256;
_tileInfo.origin = new MapPoint(-180,90);
_tileInfo.spatialReference = new SpatialReference(4326);
_tileInfo.lods = [
//new LOD(0,1.40625,590995197.1416691),
new LOD(1,0.703125,295497598.5708346),
new LOD(2,0.3515625,147748799.2854173),
new LOD(3,0.17578125,73874399.64270864),
new LOD(4,0.087890625,36937199.82135432),
new LOD(5,0.0439453125,18468599.91067716),
new LOD(6,0.02197265625,9234299.95533858),
new LOD(7,0.010986328125,4617149.97766929),
new LOD(8,0.0054931640625,2308574.98883465),
new LOD(9,0.00274658203124999,1154287.49441732),
new LOD(10,0.001373291015625,577143.747208662),
new LOD(11,0.0006866455078125,288571.873604331),
new LOD(12,0.000343322753906249,144285.936802165),
new LOD(13,0.000171661376953125,72142.9684010827),
new LOD(14,0.0000858306884765626,36071.4842005414),
new LOD(15,0.0000429153442382813,18035.7421002707),
new LOD(16,0.0000214576721191406,9017.87105013534),
];
}
private function padString(text:String,size:int,ch:String):String
{
while (text.length < size)
{
text = ch + text;
}
return text;
}
public function set url(val:String):void
{
this._url = val;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600"
creationComplete="init()" xmlns:esri="http://www.esri.com/2008/ags">
<fx:Script>
<![CDATA[
import ext.SXGeoTileLayer;
private function init():void{
var wmslayer:SXGeoTileLayer=new SXGeoTileLayer();
wmslayer.url=" http://tile0.tianditu.com/DataServer?T=A0610_ImgAnno";
map.addLayer(wmslayer);
var wmslayer1:SXGeoTileLayer=new SXGeoTileLayer();
wmslayer1.url=" http://tile0.tianditu.com/DataServer?T=sbsm0210"; map.addLayer(wmslayer1); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <esri:Map id="map"> </esri:Map> </s:Application>