<UserControl x:Class="SilverlightApplication1.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"><Grid x:Name="LayoutRoot" Background="White">
<m:Map x:Name="myMap" Center="25.858531, -80.119744" CredentialsProvider="[BINGMAPSKEY]" ZoomLevel="19" Mode="AerialWithLabels"></m:Map>
</Grid>
</UserControl>
有两种方法可以添加增强版鸟瞰图及街景(Streetside):(1) 在导航栏增加按钮 (2) 使用地图控件中的map mode扩展类。
在导航栏增加增强版鸟瞰图及街景(Streetdide)
如果你只是希望在地图导航栏增加鸟瞰图和街景按钮,只需要增加1-2行代码。首先在MainPage.xaml.cs文件的申明(declaration)中增加ExtendedModes。然后在初始化地图的代码中增加鸟瞰图和街景图模式:
using System;
using System.Windows.Controls;
using Microsoft.Maps.MapControl.ExtendedModes;
using Microsoft.Maps.MapControl.Core;namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();//Add Bird's Eye to Navigation
BirdseyeMode.AddModeToNavigationBar(myMap);//Add Streetside to Navigation
StreetsideMode.AddModeToNavigationBar(myMap);
}
}
}
自定义控制增加增强版鸟瞰图及街景(Streetside)
如果你希望自定义控制显示鸟瞰图及街景,你可以使用Map.Mode类。此处,你需要增加一个申明:using Microsoft.Maps.MapControl.Core
以下的代码在加载地图时显示鸟瞰图:
using System;
using System.Windows.Controls;
using Microsoft.Maps.MapControl.ExtendedModes;
using Microsoft.Maps.MapControl.Core;namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{InitializeComponent();
myMap.Mode = new BirdseyeMode();
myMap.Mode.Center = new Microsoft.Maps.MapControl.Location(25.859768, -80.119764);
myMap.Mode.ZoomLevel = 17;}
}
}
以下代码在加载地图时显示街景:
using System;
using System.Windows.Controls;
using Microsoft.Maps.MapControl.ExtendedModes;
using Microsoft.Maps.MapControl.Core;namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{InitializeComponent();
myMap.Mode.Center = new Microsoft.Maps.MapControl.Location(47.615594, -122.20136);
myMap.Mode = new StreetsideMode();
myMap.Heading = 20.3;
myMap.Pitch = 12.3;}
}
}
此处用到了Heading和Pitch属性,其中Heading属性是指街景视图下罗盘的方向,Pitch属性控制浏览角度。以下是关于Heading和Pitch的官方定义:
Heading is the compass direction, expressed as a double. A value of 0 is true north, and a value of 180 is true south. Values less than 0 and greater than 360 are valid and are calculated as compass directions. The pitch direction, expressed as a double. A value of 0 is level and a value of -90 is straight down. Values less than -90 or greater than 0 are ignored, and the pitch is set to -90
原文参考:Chris Pendleton的博客 .