必应地图SilverLight控件入门讲座之六:显示街景(Streetside)

必应地图SilverLight控件入门讲座之六:显示街景(Streetside)

必应地图Beta版,必应地图SilverLight控件(Bing Maps Silverlight Control)也发布了最新的1.0.1.0版。开发人员可以在SilverLight版的必应地图应用中增加微软街景(Streetside)以及增强版鸟瞰图(Bird's Eye)。如果你还不知道微软必应地图Beta版,请阅读 微软推出必应地图街景http://maps.bing.com/explore
 
在开发之前,我们需要先从 Microsoft Connect 下 载最新的DLL,一个.MSI (Microsoft Installer)安装文件,其中包括了Bing Maps Silverlight Control Extended Modes Beta SDK,将会增加Microsoft.Maps.MapControl.ExtendedModes.dll在[Program Files (x86)]\Bing Maps Silverlight Control Extended Modes\Beta\Libraries\目录下。
当然,你也需要 下载新的Bing Maps SilverLight Control , 其中也包括了更新后的Microsoft.Maps.MapControl.dll以及 Microsoft.Maps.MapControl.Common.dll。你将会看到这是Bing Maps SilverLight Control 1.0.1.0版,而不是原来的1.0.0.0版。
 
接下来,按照之前的讲座为你的project增加reference:
在XAML文件中需要增加一个namespace及指向Microsoft.Maps.MapControl.dll的assembly references。当然,我们需要将地图中心设为拥有街景(Streetside)的地方。你的代码应该类似:

<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的博客 .

你可能感兴趣的:(Microsoft,360,silverlight,bing,Blend)