`
holoblog
  • 浏览: 1224887 次
博客专栏
E0fcf0b7-6756-3051-9a54-90b4324c9940
SQL Server 20...
浏览量:18896
文章分类
社区版块
存档分类
最新评论

【Silverlight】Bing Maps学习系列(七):使用Bing Maps的图片系统(Tile System)

 
阅读更多

  目前包括微软必应地图在内的几乎所有在线电子地图(如:Google Maps等)都事先对地图图片(Tile)进行预处理,通过特定的算法将预处理过后的图片进行无缝的拼接,建立一套统一有规律、标准的地图映射系统。Bing Maps地图映射、坐标系以及地图Tile编码体系映射,统称为必应地图图片系统(Bing Maps Tile System)。

  如果要了解Bing Maps的地图图片系统,可以看看下面这两片文章: 

必应地图图片系统(Tile System)之一

必应地图图片系统(Tile System)之二

  了解了Bing Maps的Tile System,下面来看看如何使用Bing Maps的Tile System。首先要明确一点,地图的不同放大级别(ZoomLabel)的界面上显示的效果是又不同的多张图片组成,下面通过Tile System加载一张图片(http://images.cnblogs.com/cnblogs_com/beniao/BingMaps/China0.jpg)的示例来来证实这一说话。

<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />-->1publicMainPage()
2
{
3
InitializeComponent();
4
MapTileLayertileLayer=newMapTileLayer();
5
LocationRectTileSourcetileSource=newLocationRectTileSource(
6
newUriBuilder(@"http://images.cnblogs.com/cnblogs_com/beniao/BingMaps/China0.jpg").Uri.ToString(),
7
newLocationRect(newLocation(60,60),newLocation(13,140)),
8
newRange<double>(1,16));
9
tileLayer.TileSources.Add(tileSource);
10
tileLayer.Opacity=0.9;
11
myMap.Children.Add(tileLayer);
12
this.myMap.ViewChangeOnFrame+=delegate(objectsender,Microsoft.Maps.MapControl.MapEventArgse)
13
{
14
doublelongitude=this.myMap.Center.Longitude;
15
doublelatitude=this.myMap.Center.Latitude;
16

17this.tbLatitude.Text=latitude.ToString();
18
this.tbLongitude.Text=longitude.ToString();
19
};
20
this.myMap.Mode=newMercatorMode();
21
}

  通过上面4---11行代码,实现通过Tile System加载一张图片到地图显示出来,通过运行程序可以发现,同一张图片在设置的地图界面上显示出了多张,这是为什么呢?就是上面所声明是:“地图的不同放大级别(ZoomLabel)的界面上显示的效果是又不同的多张图片组成”,为了证实这一点我们可以通过HttpWatch等工具查看到详细的http请求响应数据:

      

      

  在本文开头部分提到,Bing Maps地图数据就是通过Tile System编码映射将不同的图片组合在一起形成的一套完整的图片系统。下面我们将上面加载图片的地址修改下,比如加载中国地区的Bing Maps,首先我们需要找到中国地图所对应的Bing Maps的Tile System映射Url(可通过HttpWatch工具在http://cn.bing.com/得到)。

      

<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />-->1namespaceUseTileLayers
2
{
3
publicpartialclassMainPage:UserControl
4
{
5
publicMainPage()
6
{
7
InitializeComponent();
8
//初始化一个Uri对象,指向中文必应地图的Tile系统
9UriBuildertileSourceUri=newUriBuilder("http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41");
10

11MapTileLayertileLayer=newMapTileLayer();//初始化一个图层
12LocationRectTileSourcetileSource=newLocationRectTileSource(
13
tileSourceUri.Uri.ToString(),
14
newLocationRect(newLocation(60,60),newLocation(13,140)),
15
//初始化LocationRectTileSource对象,设定显示范围及放大级别
16newRange<double>(1,16));
17
tileLayer.TileSources.Add(tileSource);//指定图层的TileSource
18tileLayer.Opacity=0.9;
19
myMap.Children.Add(tileLayer);//将图层叠加在地图上
20
21this.myMap.ViewChangeOnFrame+=delegate(objectsender,Microsoft.Maps.MapControl.MapEventArgse)
22
{
23
doublelongitude=this.myMap.Center.Longitude;
24
doublelatitude=this.myMap.Center.Latitude;
25

26this.tbLatitude.Text=latitude.ToString();
27
this.tbLongitude.Text=longitude.ToString();
28
};
29
this.myMap.Mode=newMercatorMode();
30
}
31
}
32
}

      

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics