From the previous study, we can see that in the Silverlight API, not only can we easily use the map service released by ArcGIS server9.3, but also can introduce other data sources by inheriting the corresponding layers, for example, the map service, WMS service, or other free data released by ArcGIS server9.2. This section uses an example to see how to use Google map as the basemap data.
Google map is cached data, so it inherits tiledmapservicelayer. So what do I need to do when I expand this layer? First, we must understand the principle of map caching. We can see that the layers we inherit need to collect the following information:
1. tiling scheme origin;
2. The range of the cut graph, that is, fullextent;
3. spatialreference;
4. tileinfo, including the size, level, and resolution of the cut graph;
5. Rewrite the gettileurl method.
Why? As you can imagine, when the range of the map control changes, you can get the information of the current range. You only need to display the tile between the upper left and the lower right in order. From the previous article, we can see that when layers obtain information such as 1, 2, 3, and 4, the required tile can be automatically calculated, finally, retrieve these tile entries according to the gettileurl method.
How can we obtain the first four parameters of Google map? Do you remember a loadtiling scheme from Google map when caching in catalog? According to the tilingscheme, cache a map service and view its Conf. xml and servicedirectory to obtain these parameters. In addition, there are many methods on the Internet to obtain the Google map cache, so we will not discuss it here.
Googlemap.jpg
Googlemap1.jpg
The Code is as follows:
Code:
public
class GoogleMap:TiledMapServiceLayer
{
public override void Initialize()
{
this.FullExtent = new
ESRI.ArcGIS.Geometry.Envelope(-20037508.342787,-20037508.342787,20037508.342787,20037508.342787);//(-180,
-85.0511287798066,180, 85.0511287798066)
{
SpatialReference = new ESRI.ArcGIS.Geometry.SpatialReference(102113);
};
this.SpatialReference = new ESRI.ArcGIS.Geometry.SpatialReference(102113);
//this.InitialExtent = this.FullExtent;
this.TileInfo = new TileInfo()
{
Height = 256,
Width = 256,
Origin = new ESRI.ArcGIS.Geometry.MapPoint(-20037508.342787,
20037508.342787)//Origin = new ESRI.ArcGIS.Geometry.MapPoint(-180, 90)
{
SpatialReference = new ESRI.ArcGIS.Geometry.SpatialReference(102113)
},
Lods = new Lod[20]
};
double resolution = 156543.033928;
for (int i = 0; i < TileInfo.Lods.Length; i++)
{
TileInfo.Lods[i] = new Lod() { Resolution = resolution };
resolution /= 2;
}
base.Initialize();
}
public override string GetTileUrl(int level, int row, int col)
{
//google maps map
//string baseUrl = "http://mt0.google.com/mt/v=ap.92&hl=zh-CN&x=";
//string url = baseUrl + col.ToString() + "&y=" + row.ToString() + "&z=" + level.ToString() + "&s=";
//return url;
////google maps satallite
string baseUrl = "http://khm2.google.com/kh/v=38&hl=zh-CN&x=";
string url = baseUrl + col.ToString() + "&y=" + row.ToString() + "&z=" + level.ToString() + "&s=";
return url;
}
}
Note that Google map uses the WGS 1984 web Mercator projection. The wkid of this projection cannot be found in restapi, but it can be found in servicedirecotry, Which is 102113. In addition, rewriting dynamicmapservicelayer is basically the same.
Then, you can cache your services according to the tiling scheme, so that your data and Google map can be combined. However, data using GoogleMap is not only worried about being blocked by IP addresses, but also copyright issues. After all, it is not like js api (with ArcGIS JavaScript extension forthe Google Maps API) or flex API (with Google map API forflex ). Don't forget that Ms has its own Virtual Earth. In the next section, let's take a look at how to use ve data in our program.
From: http://www.gisall.com/html/32/7232-1270.html