搜狗地图的TMS算法与谷歌地图大同小异,但是就因为这点差异,要浪费一些时间去修改代码。不多说,直接上代码,给大家分享。
package util
{
import com.esri.ags.SpatialReference;
import com.esri.ags.geometry.Extent;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.layers.TiledMapServiceLayer;
import com.esri.ags.layers.supportClasses.LOD;
import com.esri.ags.layers.supportClasses.TileInfo;
import flash.net.URLRequest;
import mx.events.Request;
public class SogouTileMapServiceLayer extends TiledMapServiceLayer
{
private var mapMinZoom:int = 1; //最小显示等级
private var mapMaxZoom:int = 18;//最大显示等级
//成员变量
private var _tileInfo:TileInfo = new TileInfo(); // see buildTileInfo()
private var tileUrls:Array = [
"http://p0.go2map.com/seamless1/0/174/",
"http://p1.go2map.com/seamless1/0/174/",
"http://p2.go2map.com/seamless1/0/174/",
"http://p3.go2map.com/seamless1/0/174/"];
public function SogouTileMapServiceLayer()
{
super();
buildTileInfo(); // to create our hardcoded tileInfo
setLoaded(true); // Map will only use loaded layers
}
override public function get fullExtent():Extent
{
return new Extent(-180,-90,180,90, new SpatialReference(4326));
}
override public function get initialExtent():Extent
{
return new Extent(-180,-90,180,90, 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(zoom:Number, row:Number, col:Number):URLRequest
{
zoom = zoom - 2;
var offsetX:Number = Math.pow(2,zoom);
var offsetY:Number = offsetX - 1;
var numX:Number = col - offsetX;
var numY:Number = (-row) + offsetY;
zoom = zoom + 1;
var l:int = 729 - zoom;
if (l == 710) l = 792;
var blo:Number = Math.floor(numX / 200);
var bla:Number = Math.floor(numY / 200);
var blos:String,blas:String;
if (blo < 0)
blos = "M" + ( - blo);
else
blos = "" + blo;
if (bla < 0)
blas = "M" + ( - bla);
else
blas = "" + bla;
var x:String = numX.toString().replace("-","M");
var y:String = numY.toString().replace("-","M");
var num:int = (row+col) % tileUrls.length;
trace(l+" row:"+blos+" col: "+blas+" x: "+x+" y: "+y);
var strURL:String = "";
strURL = tileUrls[num] + l + "/" + blos + "/" + blas + "/" + x + "_" + y + ".GIF";
var urlRequest:URLRequest;
urlRequest = new URLRequest(strURL);
return urlRequest;
}
private function buildTileInfo():void
{
//北京wgs84 墨卡托:3242230,11674840
_tileInfo.height=256;
_tileInfo.width=256;
_tileInfo.origin=new MapPoint(0,0);
_tileInfo.lods = [
//new LOD(0, 1.4047193659, 591657527.591555),
new LOD(1, 0.702359682, 295828763.795777),
new LOD(2, 0.351179841, 147914381.897889),
new LOD(3, 0.175589920, 73957190.948944),
new LOD(4, 0.087794960372, 36978595.474472),
new LOD(12, 0.00034294, 144447.638572),
new LOD(13, 0.0001714745, 72223.819286),
new LOD(14, 0.000085737265, 36111.909643),
new LOD(15, 0.0000428686329, 18055.954822),
new LOD(16, 0.000021434316, 9027.977411),
new LOD(17, 0.00001071715824, 4513.988705),
new LOD(18, 0.0000053585791250, 2256.994353),
];
}
}
}
效果如下: