地図の制御
コードから簡単な地図の制御をしてみましょう。MainPage.
Imports Microsoft.Maps.MapControl
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
' 道路地図か航空写真(ラベル表示の有無)かの設定
MyMap.Mode = New AerialMode With {.Labels = True}
' または MyMap.Mode = New RoadMode
' MyMap.SetMode(New RoadMode, False) など
' ズームレベル(1が最小値でズームアウトした状態)の設定
MyMap.ZoomLevel = 10
' 地図の中心に表示する 緯度・経度の設定
MyMap.Center = New Location(36.0999, 139.6549)
' または MyMap.SetView(New Location(36.0999, 139.6549), 10) など
End Sub
End Class
コードを見ていただけると直感的にわかるのではないかと思います。道路地図・
<m:Map x:Name="MyMap" CredentialsProvider="取得したKey"
Mode="AerialWithLabels" ZoomLevel="10" Center="36.0999,139.6549"/>
SilverlightやWPFの特徴であるデータバインディングももちろん使用できます。次のようにXAMLを編集し,
<UserControl x:Class="BingMapsApp.MainPage"
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:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
xmlns:me="clr-namespace:BingMapsApp"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<me:LocationConverter x:Key="LocationConverter" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox x:Name="LocationTextBox" Text="36.0999,139.6549" />
<m:Map x:Name="MyMap"
Grid.Row="1" CredentialsProvider="取得したKey"
Mode="AerialWithLabels" ZoomLevel="10"
Center="{Binding ElementName=LocationTextBox, Path=Text, Mode=TwoWay, Converter={StaticResource LocationConverter}}"/>
</Grid>
</UserControl>
Imports System.Windows.Data
Imports Microsoft.Maps.MapControl
Public Class LocationConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Try
Dim values = CStr(value).Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
Return New Location(CDbl(values(0)), CDbl(values(1)))
Catch ex As Exception
Return DependencyProperty.UnsetValue
End Try
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Try
Dim location = DirectCast(value, Location)
Return String.Format("{0},{1}", location.Latitude, location.Longitude)
Catch ex As Exception
Return DependencyProperty.UnsetValue
End Try
End Function
End Class
上記コードの実行結果は図7のようになります。
Interactive SDK
今回紹介できた内容はBing Maps Silverlight Control SDKのほんの一部分だけです。ですが,
Interactive SDKでは,
おわりに
今回は以上です。いかがでしたでしょうか。LiveブランドからBingブランドへと変わり,