Search code examples
c#.netwpfwinformsbing-maps

How can I set the Bing Map style?


I want to set the map style based on user selection (between aerial, birdseye, road, and streetside) in my Winforms app.

I've got this code:

using Microsoft.Maps.MapControl.WPF;
. . .

private void aerialToolStripMenuItem_Click(object sender, EventArgs e)
{
    userControl11.myMap.Style = Microsoft.Maps.MapTypeId.aerial;
}

...which won't compile, as it tells me:

enter image description here

I do have Microsoft.Maps.MapControl.WPF in my References.

Also, when I tried this code:

this.userControl11.myMap.Style = Microsoft.Maps.MapControl.WPF.AerialMode;

...I got, "AerialMode is a type, which is not valid in the given context"

BTW, I have this for rendering the map control:

<UserControl x:Class="MyMaps.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF">
    <Grid>
        <m:Map CredentialsProvider="gr8GooglyMoogly" x:Name="myMap" />
    </Grid>
</UserControl>

UPDATE

Based on the answer and comments, I am now successfully using these for the three available "modes":

this.userControl11.myMap.Mode = new AerialMode(); // Aerial
this.userControl11.myMap.Mode = new AerialMode(true); // Aerial with Labels
this.userControl11.myMap.Mode = new RoadMode(); // Road

Solution

  • You are looking for Mode property and you need to assign a new instance of AerialMode to it:

    this.userControl11.myMap.Mode = new Microsoft.Maps.MapControl.WPF.AerialMode();
    

    If you want it to show labels, pass true to the constructor of AerialMode. You can learn more about map views and modes in: Understanding Map Views.

    enter image description here