esri tilemap四叉树索引和google map 的四叉树索引是有区别的,区别在于
google map在第一次分幅的时候分为4片,但esri tilemap只分为2片,相当于在
第三和第四象限没有图。只有(0,0)(0,1)的时候才有图,这就造成了google
map和esri tilemap融合的时候比较复杂,不能使用相同的分幅方法。
在下面的例子里,实现了根据nzoom,以及经纬度取esri服务器上对应的图片。
图片是512*512的。这个算法是用flex来实现的,也可以用其他语言去实现,然后
从服务器上裁图。(注意大家不要搞N个线程去下arcgisonline上的数据,不然会
把arcgisonline的服务搞挂的O(∩_∩)O哈哈~)
什么都不多说了,直接放代码。
Code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:esri="http://www.esri.com/2008/ags"
layout="absolute"
>
<mx:Script>
<![CDATA[
import com.esri.ags.geometry.MapPoint;
import mx.containers.HBox;
import mx.containers.VBox;
import mx.controls.Image;
import mx.rpc.events.ResultEvent;
//导入flash的命名空间
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.Button;
import mx.rpc.AsyncResponder;
import flash.geom.Point;
import mx.rpc.events.FaultEvent;
import mx.printing.FlexPrintJobScaleType;
import mx.printing.FlexPrintJob;
import mx.rpc.soap.mxml.Operation;
import mx.containers.Canvas;
import flash.text.*;
import mx.controls.Text;
private function GetURL(nZoom:int,mp:Point):String
{
var url:String = new String();
url = "";
if(nZoom < 0 ||nZoom>15)
return url;
if(mp.x >180||mp.x<-180 ||mp.y>90||mp.y<-90)
return url;
var pnt:Point = GetTileXY(nZoom,mp);
url =
"http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_Wor
ld_2D/MapServer/tile/"+nZoom.toString()+"/"+pnt.y.toString()
+"/"+pnt.x.toString();
return url;
}
private function GetTileXY(nZoom:int,mp:Point):Point
{
var wx:Number;
var wy:Number;
var cx:Number;
var cy:Number;
var xArray:Array = new Array();
var yArray:Array = new Array();
cx = 0;
cy = -90;
wx = wy = 180;
var i:int = 0;
var x:int = 0;
var y:int = 0;
for (i = 0; i <= nZoom; i++)
{
if (mp.x >= cx)
{
if (mp.y >= cy)
{
xArray.push(1);
yArray.push(0);
cx += wx/2;
cy += wy/2;
}
else
{
xArray.push(1);
yArray.push(1);
cx += wx/2;
cy -= wy/2;
}
}
else
{
if (mp.y < cy)
{
xArray.push(0);
yArray.push(1);
cx -= wx/2;
cy -= wy/2;
}
else
{
xArray.push(0);
yArray.push(0);
cx -= wx/2;
cy += wy/2;
}
}
wx = wx/2;
wy = wy/2;
}
for(i = nZoom;i >=0;i--)
{
x = x+xArray[i]*Math.pow(2,nZoom-i);
y = y+yArray[i]*Math.pow(2,nZoom-i);
}
var pnt :Point = new Point(x,y);
return pnt;
}
private function OnClick():void
{
var zoom :int = new int(nZoom.text);
var x:Number = new Number(Lon.text) ;
var y:Number = new Number(Lat.text);
var pnt:Point = new Point(x,y);
var url :String = GetURL(zoom,pnt);
myImage.load(url);
}
]]>
</mx:Script>
<mx:VBox>
<mx:Panel id = "myPanel" width="512" height="512">
<mx:Image id = "myImage" width="100%"
height="100%"/>
</mx:Panel>
<mx:HBox>
<mx:VBox>
<mx:HBox>
<mx:Label text="级别"/>
<mx:TextInput width="30%" id="nZoom"
text="2" enter="OnClick()"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="纬度"/>
<mx:TextInput width="30%" id="Lat"
text="40" enter="OnClick()"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="经度"/>
<mx:TextInput width="30%" id="Lon"
text="116" enter="OnClick()"/>
</mx:HBox>
</mx:VBox>
<mx:Button label="GetImage" click="OnClick()"/>
</mx:HBox>
</mx:VBox>
</mx:Application>
原文地址:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=35712&extra=page%3D3%26amp%3Borderby%3Ddateline
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:esri="http://www.esri.com/2008/ags"
layout="absolute"
>
<mx:Script>
<![CDATA[
import com.esri.ags.geometry.MapPoint;
import mx.containers.HBox;
import mx.containers.VBox;
import mx.controls.Image;
import mx.rpc.events.ResultEvent;
//导入flash的命名空间
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.Button;
import mx.rpc.AsyncResponder;
import flash.geom.Point;
import mx.rpc.events.FaultEvent;
import mx.printing.FlexPrintJobScaleType;
import mx.printing.FlexPrintJob;
import mx.rpc.soap.mxml.Operation;
import mx.containers.Canvas;
import flash.text.*;
import mx.controls.Text;
private function GetURL(nZoom:int,mp:Point):String
{
var url:String = new String();
url = "";
if(nZoom < 0 ||nZoom>15)
return url;
if(mp.x >180||mp.x<-180 ||mp.y>90||mp.y<-90)
return url;
var pnt:Point = GetTileXY(nZoom,mp);
url =
"http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_Wor
ld_2D/MapServer/tile/"+nZoom.toString()+"/"+pnt.y.toString()
+"/"+pnt.x.toString();
return url;
}
private function GetTileXY(nZoom:int,mp:Point):Point
{
var wx:Number;
var wy:Number;
var cx:Number;
var cy:Number;
var xArray:Array = new Array();
var yArray:Array = new Array();
cx = 0;
cy = -90;
wx = wy = 180;
var i:int = 0;
var x:int = 0;
var y:int = 0;
for (i = 0; i <= nZoom; i++)
{
if (mp.x >= cx)
{
if (mp.y >= cy)
{
xArray.push(1);
yArray.push(0);
cx += wx/2;
cy += wy/2;
}
else
{
xArray.push(1);
yArray.push(1);
cx += wx/2;
cy -= wy/2;
}
}
else
{
if (mp.y < cy)
{
xArray.push(0);
yArray.push(1);
cx -= wx/2;
cy -= wy/2;
}
else
{
xArray.push(0);
yArray.push(0);
cx -= wx/2;
cy += wy/2;
}
}
wx = wx/2;
wy = wy/2;
}
for(i = nZoom;i >=0;i--)
{
x = x+xArray[i]*Math.pow(2,nZoom-i);
y = y+yArray[i]*Math.pow(2,nZoom-i);
}
var pnt :Point = new Point(x,y);
return pnt;
}
private function OnClick():void
{
var zoom :int = new int(nZoom.text);
var x:Number = new Number(Lon.text) ;
var y:Number = new Number(Lat.text);
var pnt:Point = new Point(x,y);
var url :String = GetURL(zoom,pnt);
myImage.load(url);
}
]]>
</mx:Script>
<mx:VBox>
<mx:Panel id = "myPanel" width="512" height="512">
<mx:Image id = "myImage" width="100%"
height="100%"/>
</mx:Panel>
<mx:HBox>
<mx:VBox>
<mx:HBox>
<mx:Label text="级别"/>
<mx:TextInput width="30%" id="nZoom"
text="2" enter="OnClick()"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="纬度"/>
<mx:TextInput width="30%" id="Lat"
text="40" enter="OnClick()"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="经度"/>
<mx:TextInput width="30%" id="Lon"
text="116" enter="OnClick()"/>
</mx:HBox>
</mx:VBox>
<mx:Button label="GetImage" click="OnClick()"/>
</mx:HBox>
</mx:VBox>
</mx:Application>