Last month, acnchen, Business Development Manager of Bing (Bing Maps) Greater China, published an article titled loading other Maps (Google satellite Maps, etc.) in the Bing map SilverLight control, it details how to load Google satellite maps. This article is similar to this article. In addition to Google satellite Maps on the internet, Bing Maps Silverlight Control can also load custom Google Maps map data, including satellite maps and traffic map.
First, let's review how Bing Maps Silverlight Control loads Google satellite Maps. Its principle is to create a TileSource for Google satellite Maps and implement the Google satellite map loading algorithm in this TileSource, it is mainly to construct a correct TileSource ing Url. The Url format can be obtained through HTTP sniffer tools such as HttpWatch.
1 public class GoogleTileSource: TileSource
2 {
3 public GoogleTileSource ()
4: base ("http: // khm {0} .google.com/kh/v?47&x==1}&y=%2}&z=%3 }")
5 {}
6
7 public override Uri GetUri (int x, int y, int zoomLevel)
8 {
9 return new Uri (string. Format (this. UriFormat, x % 4, x, y, zoomLevel ));
10}
11}
The above completes the Url Algorithm for Google's online satellite map data, and it is OK to use the TileSource on the front end.
1 public partial class MainPage: UserControl
2 {
3 public MainPage ()
4 {
5 InitializeComponent ();
6
7 MapTileLayer tileLayer = new MapTileLayer ();
8 GoogleTileSource gts = new GoogleTileSource ();
9 tileLayer. TileSources. Add (gts );
10 myMap. Children. Add (tileLayer );
11 this. myMap. Mode = new MercatorMode ();
12}
13}
As shown in the preceding figure, Google's online satellite map is loaded. Although the function is implemented, it is still not perfect. If we are not connected to the internet, we cannot load the map. Therefore, we need to deploy the map data ourselves, how can we load map data for custom deployment? Google map data is actually very simple. You just need to deploy the map data through a Web server (such as IIS.
After completing the deployment of map data, you can develop the TileSource Url ing algorithm based on the self-deployed map data, then, you can load and present your deployed map data in the same way as loading Google online map data. Modify the algorithm used to load online map data so that it can adapt to loading Google Maps data deployed by itself.
1 public class GoogleTileSource: TileSource
2 {
3 public GoogleTileSource ()
4: base ("http: // localhost: 5000/CQ _ {0}/1271316-41022.16.png ")
5 {}
6
7 public override Uri GetUri (int x, int y, int zoomLevel)
8 {
9 int port = Application. Current. Host. Source. Port;
10
11 string url = string. format (this. uriFormat, (zoomLevel + 1 ). toString ("D2"), (y + 1 ). toString ("D6"), (x + 1 ). toString ("D6"), port );
12 return new Uri (url );
13} compile and run the above program again. You can see that you have successfully loaded and presented your deployed Google Maps data ~~~~~~. With Google map data, you don't have to worry about the trouble of loading maps without network connection. If you don't think the effect is very good, you can set a background color for the map, which is much better than online Google Maps. We have loaded Road Condition maps in our self-deployed map data above. In fact, we can also load Google satellite maps from our self-deployed map data server, which is as simple as loading road condition maps, on this basis, you only need to make small changes to achieve the goal. In the Google Maps map data, the Tile Source algorithm of the road condition map and the satellite map is the same, but different types of images are used. The preceding path map is as follows:
1 public GoogleTileSource ()
2: base ("http: // localhost: 5000/CQ _ {0}/1271316-41022.16.png ")
3 {}
To load a satellite map on the map data server deployed by yourself, you only need to modify the image watermark of Tile systemururlto .jpg, as shown in the following code block:
1 public GoogleTileSource ()
2: base ("http: // localhost: 5000/CQ _ {0}/1271316-000022.16.jpg ")
3 {}
In this way, the satellite map can be loaded, and the compilation and running program will feel that some layers are not loaded. This is due to the incorrect TileSource image Url ing Url ing calculation, we will not introduce the large-level algorithms of different map parties here. We hope to introduce more, better, and deeper technical articles through this article.
Description
This document is a learning note and is intended to be shared with people with lofty ideals. You are welcome to repost this article, but mark the original article connection in a prominent position.
Author: Beniao WebGIS development group: 75662563
Article Source: http://beniao.cnblogs.com/or http://www.cnblogs.com/