天地图地图服务的读取例子在前两年已经有了成果,在这里为了补全系列专题的完整性,给出代码,仅供参数,除了图片获取函数与其它不同,其它跟前两专题的方法是保持一致的。
public class NGCCTiledMapLayer : TiledMapServiceLayer
{
//****************根据天地图的实际地址修改 {baseUrl} 参数*************//
// privateconst string baseUrl ="http://map.sxch.gov.cn:7001/geoglobe/DataServer?T=china400&";
privateconst stringbaseUrl1 = "http://tile";
// privateconst string baseUrl2 = ".tianditu.com/DataServer?T=A0512_EMap&";
privateconst stringbaseUrl2 = ".tianditu.com/DataServer?T=B0627_EMap1112&";
System.Randomra = new System.Random();
privateconst int WKID= 4326;
public override voidInitialize()
{
//图层的全图范围
this.FullExtent= new ESRI.ArcGIS.Client.Geometry.Envelope(-180,-90,180,90)
{
SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(WKID)
};
//图层的空间参考
this.SpatialReference= new ESRI.ArcGIS.Client.Geometry.SpatialReference(WKID);
//设置切片的信息. 每个切片的大小256x256px, 14级
this.TileInfo= new TileInfo()
{
Height = 256,
Width = 256,
Origin = new ESRI.ArcGIS.Client.Geometry.MapPoint(-180, 90) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(WKID) },
Lods = new ESRI.ArcGIS.Client.Lod[20]
};
//设置每一级别的分辨率.每一级别的分辨率都是前一个级别的一半
doubleresolution = 0.70391441567318025 * 1.99775;//**************** 根据天地图的实际地址修改调节系数 *************//
for(int i = 0; i < TileInfo.Lods.Length; i++)
{
TileInfo.Lods[i] = new Lod() {Resolution = resolution};
resolution /= 2;
}
//调用初始化事件
base.Initialize();
}
///返回指定切片的url
public override stringGetTileUrl(int level, introw, int col)
{
returnbaseUrl1 + ra.Next(1, 7).ToString() + baseUrl2 + "L="+ level.ToString() + "&X=" +col.ToString() + "&Y=" +row.ToString();
//returnbaseUrl + "L=" + level.ToString() + "&X=" +col.ToString() + "&Y=" + row.ToString();
}
}