Silverlight学习笔记十七BingMap(六)之获取图片系统的图片信息ImageryService的应用
2010-08-23 10:50
681 查看
BIngMap的ImageryService服务是一个微软发布的WCF服务,它用来获取图片系统的图片信息.服务地址:http://dev.virtualearth.net/webservices/v1/imageryservice/ImageryService.svc
本例中使用的是中文图片系统
效果如图
![](http://pic002.cnblogs.com/img/875867090/201008/2010082310491616.png)
一、获取中文图片系统类(ChinaTileSource.cs)
public class ChinaTileSource
{
/// <summary>
/// 加载中国地图系统
/// http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41中国地图系统
/// </summary>
/// <returns>TileSource</returns>
public TileSource GetChinaTileSource()
{
UriBuilder tileSourceUri = new UriBuilder("http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41");
MapTileLayer tileLayer = new MapTileLayer();
LocationRectTileSource tileSource = new LocationRectTileSource(tileSourceUri.Uri.ToString()
, new LocationRect(new Location(60, 60), new Location(13, 140)), new Range<double>(1, 16));
return tileSource;
}
}
二、使用中文图片系统
/// <summary>
/// 中文图片系统
/// </summary>
public ImageryServiceDemo()
{
InitializeComponent();
MapTileLayer tileLayer = new MapTileLayer();
ChinaTileSource gts = new ChinaTileSource();
tileLayer.TileSources.Add(gts.GetChinaTileSource());
myMap.Children.Add(tileLayer);
}
三.获取图片信息
1.前台
<UserControl x:Class="SlBindMapDemo.ImageryServiceDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:map="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="800">
<Grid x:Name="LayoutRoot" Background="White">
<map:Map x:Name="myMap" Grid.Row="0" Height="300" Width="400" Center="33.845881352,105.165628188471"
NavigationVisibility="Collapsed" Mode="Road" CredentialsProvider="AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC" >
</map:Map>
<Border BorderBrush="Gray" BorderThickness="3,3,3,3"
Margin="3,3,3,3" HorizontalAlignment="Right"
Opacity="0.78" Height="160" Background="#A82D2D2D"
VerticalAlignment="Top" CornerRadius="5,5,5,5">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<TextBlock Text="经度:"></TextBlock>
<TextBox x:Name="tbLongitude" Width="130"></TextBox>
<TextBlock Text="纬度:"></TextBlock>
<TextBox x:Name="tbLatitude" Width="130"></TextBox>
<TextBlock Text="缩放级别:"></TextBlock>
<TextBox x:Name="tbZoomLevel" Width="30"></TextBox>
<Button x:Name="btnImageMetadata" Click="btnImageMetadata_Click" Content="获取图片映射地址" Margin="3"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<TextBlock Text="映射地址:"></TextBlock>
<TextBox x:Name="tbMetadataResult" Width="500"></TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<TextBlock Text="图片高度:"></TextBlock>
<TextBox x:Name="tbHeight" Width="150"></TextBox>
<TextBlock Text="图片宽度:"></TextBlock>
<TextBox x:Name="tbWidth" Width="150"></TextBox>
<Button Content="生产图片" Click="btnGetUrl_Click"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image x:Name="imgMap"></Image>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</UserControl>
2.后台
/// <summary>
/// 获取图片地址
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnImageMetadata_Click(object sender, RoutedEventArgs e)
{
//构造服务请求对象
var request = new ImageryMetadataRequest();
request.Credentials = new Credentials();
request.Credentials.ApplicationId = "AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC";
//设置地理位置经度、纬度和地图缩放级别,从界面控件收集值
var location = new Location(double.Parse(this.tbLatitude.Text), double.Parse(this.tbLongitude.Text));
request.Options = new ImageryMetadataOptions();
request.Options.Location = location;
request.Options.ZoomLevel = int.Parse(this.tbZoomLevel.Text);
request.Style = MapStyle.Road;
//构造ImageryService客户端代理对象实例
var client = new ImageryServiceClient();
client.GetImageryMetadataCompleted += (o, args) => //处理请求的响应接口
{
if (args.Error == null)
{
var response = args.Result;
this.tbMetadataResult.Text = response.Results[0].ImageUri.ToString();
this.tbHeight.Text = response.Results[0].ImageSize.Height.ToString();
this.tbWidth.Text = response.Results[0].ImageSize.Width.ToString();
}
};
//发起异步调用
client.GetImageryMetadataAsync(request);
}
四、生成图片
1.前台
我在这里定义了一个Image用它来存放生成的图片
<StackPanel Orientation="Horizontal">
<Image x:Name="imgMap"></Image>
</StackPanel>
1.后台
/// <summary>
/// 生成图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGetUrl_Click(object sender, RoutedEventArgs e)
{
var request = new MapUriRequest();
request.Credentials = new Microsoft.Maps.MapControl.Credentials();
//申请的BIngMap ID
request.Credentials.ApplicationId = "AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC";
request.Center = new Location(35.0521567883562, 100.81816585252);
var opt = new MapUriOptions();
//图片的模式
opt.Style = MapStyle.AerialWithLabels;
opt.ZoomLevel = 4;
opt.ImageSize = new SizeOfint();
opt.ImageSize.Height = int.Parse(tbHeight.Text);
opt.ImageSize.Width = int.Parse(tbWidth.Text);
request.Options = opt;
var client = new ImageryServiceClient();
client.GetMapUriCompleted += (o, args) =>
{
var response = args.Result;
imgMap.Source = new BitmapImage(new Uri(response.Uri, UriKind.RelativeOrAbsolute));
};
client.GetMapUriAsync(request);
}
本例中使用的是中文图片系统
效果如图
![](http://pic002.cnblogs.com/img/875867090/201008/2010082310491616.png)
一、获取中文图片系统类(ChinaTileSource.cs)
public class ChinaTileSource
{
/// <summary>
/// 加载中国地图系统
/// http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41中国地图系统
/// </summary>
/// <returns>TileSource</returns>
public TileSource GetChinaTileSource()
{
UriBuilder tileSourceUri = new UriBuilder("http://r2.tiles.ditu.live.com/tiles/r{quadkey}.png?g=41");
MapTileLayer tileLayer = new MapTileLayer();
LocationRectTileSource tileSource = new LocationRectTileSource(tileSourceUri.Uri.ToString()
, new LocationRect(new Location(60, 60), new Location(13, 140)), new Range<double>(1, 16));
return tileSource;
}
}
二、使用中文图片系统
/// <summary>
/// 中文图片系统
/// </summary>
public ImageryServiceDemo()
{
InitializeComponent();
MapTileLayer tileLayer = new MapTileLayer();
ChinaTileSource gts = new ChinaTileSource();
tileLayer.TileSources.Add(gts.GetChinaTileSource());
myMap.Children.Add(tileLayer);
}
三.获取图片信息
1.前台
<UserControl x:Class="SlBindMapDemo.ImageryServiceDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:map="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="800">
<Grid x:Name="LayoutRoot" Background="White">
<map:Map x:Name="myMap" Grid.Row="0" Height="300" Width="400" Center="33.845881352,105.165628188471"
NavigationVisibility="Collapsed" Mode="Road" CredentialsProvider="AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC" >
</map:Map>
<Border BorderBrush="Gray" BorderThickness="3,3,3,3"
Margin="3,3,3,3" HorizontalAlignment="Right"
Opacity="0.78" Height="160" Background="#A82D2D2D"
VerticalAlignment="Top" CornerRadius="5,5,5,5">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<TextBlock Text="经度:"></TextBlock>
<TextBox x:Name="tbLongitude" Width="130"></TextBox>
<TextBlock Text="纬度:"></TextBlock>
<TextBox x:Name="tbLatitude" Width="130"></TextBox>
<TextBlock Text="缩放级别:"></TextBlock>
<TextBox x:Name="tbZoomLevel" Width="30"></TextBox>
<Button x:Name="btnImageMetadata" Click="btnImageMetadata_Click" Content="获取图片映射地址" Margin="3"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<TextBlock Text="映射地址:"></TextBlock>
<TextBox x:Name="tbMetadataResult" Width="500"></TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="3,3,3,3">
<TextBlock Text="图片高度:"></TextBlock>
<TextBox x:Name="tbHeight" Width="150"></TextBox>
<TextBlock Text="图片宽度:"></TextBlock>
<TextBox x:Name="tbWidth" Width="150"></TextBox>
<Button Content="生产图片" Click="btnGetUrl_Click"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image x:Name="imgMap"></Image>
</StackPanel>
</StackPanel>
</Border>
</Grid>
</UserControl>
2.后台
/// <summary>
/// 获取图片地址
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnImageMetadata_Click(object sender, RoutedEventArgs e)
{
//构造服务请求对象
var request = new ImageryMetadataRequest();
request.Credentials = new Credentials();
request.Credentials.ApplicationId = "AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC";
//设置地理位置经度、纬度和地图缩放级别,从界面控件收集值
var location = new Location(double.Parse(this.tbLatitude.Text), double.Parse(this.tbLongitude.Text));
request.Options = new ImageryMetadataOptions();
request.Options.Location = location;
request.Options.ZoomLevel = int.Parse(this.tbZoomLevel.Text);
request.Style = MapStyle.Road;
//构造ImageryService客户端代理对象实例
var client = new ImageryServiceClient();
client.GetImageryMetadataCompleted += (o, args) => //处理请求的响应接口
{
if (args.Error == null)
{
var response = args.Result;
this.tbMetadataResult.Text = response.Results[0].ImageUri.ToString();
this.tbHeight.Text = response.Results[0].ImageSize.Height.ToString();
this.tbWidth.Text = response.Results[0].ImageSize.Width.ToString();
}
};
//发起异步调用
client.GetImageryMetadataAsync(request);
}
四、生成图片
1.前台
我在这里定义了一个Image用它来存放生成的图片
<StackPanel Orientation="Horizontal">
<Image x:Name="imgMap"></Image>
</StackPanel>
1.后台
/// <summary>
/// 生成图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGetUrl_Click(object sender, RoutedEventArgs e)
{
var request = new MapUriRequest();
request.Credentials = new Microsoft.Maps.MapControl.Credentials();
//申请的BIngMap ID
request.Credentials.ApplicationId = "AkGGA_JlwP7XGV8JxIPb8oEWxrInlLMGKpCe7QM4QB5cg4UGNCqUyjqVfC0B2-XC";
request.Center = new Location(35.0521567883562, 100.81816585252);
var opt = new MapUriOptions();
//图片的模式
opt.Style = MapStyle.AerialWithLabels;
opt.ZoomLevel = 4;
opt.ImageSize = new SizeOfint();
opt.ImageSize.Height = int.Parse(tbHeight.Text);
opt.ImageSize.Width = int.Parse(tbWidth.Text);
request.Options = opt;
var client = new ImageryServiceClient();
client.GetMapUriCompleted += (o, args) =>
{
var response = args.Result;
imgMap.Source = new BitmapImage(new Uri(response.Uri, UriKind.RelativeOrAbsolute));
};
client.GetMapUriAsync(request);
}
相关文章推荐
- Silverlight学习笔记十七BingMap(四)之部署Google地图系统
- Silverlight学习笔记十七BingMap(五)之中文地图系统
- Silverlight学习笔记十七BingMap(三)之地图的地区标识
- SilverLight学习笔记--实际应用(二) 建立一个轮盘图片展示程序
- OAF学习笔记-12- 从系统获取ID值,查出Name,在页面显示
- 学习使用Bing Maps Silverlight Control(八):自定义的Tile系统
- Linux 学习笔记_9_文件系统管理_3_/etc/fstab文件分析与磁盘配额应用
- 【学习笔记】少占用内存获取压缩图片
- 【原创】Silverlight 4学习笔记——创建可自动更新版本的桌面应用
- SilverLight商业应用程序开发---学习笔记(6)从服务器中获取数据之二
- [Cocos2d-x for WP8学习笔记] 获取系统字体
- silverlight 学习笔记 (七):Prism的第一个应用
- 分布式应用系统服务器上下线动态感知程序开发学习笔记
- OAF学习笔记-12- 从系统获取ID值,查出Name,在页面显示
- unity3d深入学习笔记1:获取系统信息
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- silverlight 学习笔记 (九):Prism与MVVM模式在silverlight中的应用
- [dialog-system]阅读笔记 - 2017__迁移学习在Q-A系统中的应用
- canvas学习笔记:canvas对图片的像素级处理--ImageData的应用
- 学习笔记之三 获取系统时间的方法汇总