SuperMap iClient for Silverlight API聚合ArcGIS server的REST服务
SuperMap iClient for Silverlight API不仅可以对接SuperMap iServerJava6R、SuperMap iServerJava2008、SuperMap ISDotNet6的服务,实现加载其对应的图层,还可以进行扩展实现第三方图层的加载。例如在项目可能用到ArcGIS的REST服务出的图片作为底图,而业务服务用的是SuperMap的,所以就要通过扩展SuperMap iClient for Silverlight API来实现加载ArcGIS的REST服务。
扩展首先要知道:
1、Bounds:图层的地理范围。
2、CRS:当前图层的坐标参考系。坐标参考系使用 EPSG 发布的代表特定椭球体、单位、地理坐标系或投影坐标系的 Well Konwn ID 值(简称 WKID)。多个图层叠加时,该属性必设。
3、TileSize:请求图片的大小。
4、Resolutions:当前图层的分辨率数组。
5、Url:当前图层地址。
这几个属性是必须知道的。
这里我们就用ERSI_StreetMap_World_2D(MapServer)为例。
http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer
在这上面我们可以得到我们想要的所有数据。
扩展类如下:
1 namespace Test
2 {
3 public enum EMapType
4 {
5 Imagery,
6 Street
7 }
8
9 public class TiledESRIOnlineMapsLayer : TiledCachedLayer
10 {
11 private const string ImageryUrl = "http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/{0}/{1}/{2}";
12 private const string StreetMapUrl = "http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/tile/{0}/{1}/{2}";
13 //private const string topoUrl = " http://services.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer/tile/{0}/{1}/{2}";
14 private const int WKID = 4326;
15
16 public override string GetTileUrl(int indexX, int indexY, int level)
17 {
18 return string.Format(this.Url, level, indexY, indexX);
19 }
20
21 public override void Initialize()
22 {
23 this.Bounds = new Rectangle2D(-179.999999, -89.999999, 179.999999, 89.999999);
24 this.CRS = new CoordinateReferenceSystem(WKID, Unit.DecimalDegree);
25 this.TileSize = 512;
26
27 double res = 0.3515625;
28 double[] resolutions = new double[16];
29 for (int i = 0; i < resolutions.Length; i++)
30 {
31 resolutions[i] = res;
32 res *= 0.5;
33 }
34 this.Resolutions = resolutions;
35
36 switch (this.MapType)
37 {
38 case EMapType.Imagery:
39 this.Url = ImageryUrl;
40 break;
41 case EMapType.Street:
42 this.Url = StreetMapUrl;
43 break;
44 }
45 base.Initialize();
46 }
47 public EMapType MapType
48 {
49 get { return (EMapType)GetValue(MapTypeProperty); }
50 set { SetValue(MapTypeProperty, value); }
51 }
52
53 public static readonly DependencyProperty MapTypeProperty = DependencyProperty.Register("MapType", typeof(EMapType), typeof(TiledESRIOnlineMapsLayer), new PropertyMetadata(new PropertyChangedCallback(OnMapTypePropertyChanged)));
54 private static void OnMapTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
55 {
56 TiledESRIOnlineMapsLayer layer = d as TiledESRIOnlineMapsLayer;
57 if (layer.IsInitialized)
58 {
59 layer.ChangedTileSource();
60 }
61 }
62
63 private void ChangedTileSource()
64 {
65 switch (this.MapType)
66 {
67 case EMapType.Imagery:
68 this.Url = ImageryUrl;
69 break;
70 case EMapType.Street:
71 this.Url = StreetMapUrl;
72 break;
73 }
74 if (!base.IsInitialized)
75 {
76 base.Initialize();
77 }
78 else
79 {
80 base.Refresh();
81 }
82 }
83
84 }
85 }
这样这个扩展类就写完了。
用法:
1 <UserControl x:Class="TestforArcGIS.Test"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:icMapping="clr-namespace:SuperMap.Web.Mapping;assembly=SuperMap.Web"
5 xmlns:local="clr-namespace:iClient60ForSilverlight"
6 >
7 <Grid x:Name="LayoutRoot" Background="White">
8 <icMapping:Map x:Name="MyMap" >
9 <local:TiledArcGISMapsLayer/>
10 </icMapping:Map>
11 </Grid>
12 </UserControl>
效果图: