继承TiledMapServiceLayer,实现GetTileUrl方法。
public class OpenStreetMapLayer : TiledMapServiceLayer
{
private static string[] subDomains = { "a","b","c" };
private const string baseUrl = "http://{0}.tile.openstreetmap.org/{1}/{2}/{3}.png";
public override void Initialize()
{
this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892)
{
SpatialReference = new SpatialReference(102113)
};
double cornerCoordinate = 20037508.3427892;//from wkid 3857/102100
// This layer's spatial reference
this.SpatialReference = new SpatialReference(102113);
// Set up tile @R_255_4045@ion. Each tile is 256x256px,19 levels.
this.TileInfo = new TileInfo()
{
Height = 256,
Width = 256,
Origin = new MapPoint(-cornerCoordinate,cornerCoordinate) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102113) },
Lods = new Lod[19]
};
// Set the resolutions for each level. Each level is half the resolution of the prevIoUs one.
double resolution = cornerCoordinate * 2 / 256;
for (int i = 0; i < TileInfo.Lods.Length; i++)
{
TileInfo.Lods[i] = new Lod() { Resolution = resolution };
resolution /= 2;
}
// Call base initialize to raise the initialization event
base.Initialize();
}
public override string GetTileUrl(int level,int row,int col)
{
// Select a subdomain based on level/row/column so that it will always
// be the same for a specific tile. Multiple subdomains allows the user
// to load more tiles simultanously. To take advantage of the browser cache
// the following expression also makes sure that a specific tile will always
// hit the same subdomain.
string subdomain = subDomains[(level + col + row) % subDomains.Length];
return string.Format(baseUrl,subdomain,level,col,row);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。