Export (0) Print
Expand All

Map class

Bing

Represents a map. This class inherits from the Control class.

Constructor

Definition Description

Map()

Initializes a new instance of the Map class.

Properties

Name Type Databindable Description

Bounds

LocationRect

No

Gets a rectangle that defines the map view.

Center

Location

No

Gets or sets the location of the center of the map.

Children

MapUIElementCollection

No

Gets any UI elements that are children of the map control element.

CopyrightPosition

MapForegroundPosition

No

Gets or sets the position of the map copyright string.

Credentials

String

Yes

Gets or sets the map credentials used to authenticate the map.

Culture

String

Yes

Gets or sets the culture code to use. For a list of supported cultures, see Language Support.

DirectionsManager

DirectionsManager Class

No

Gets the directions manager for the map.

DirectionsRenderOptions

DirectionsRenderOptions

No

Gets or sets the options for rendering route directions.

DirectionsUIEventManager

DirectionsUIEventManager

No

Gets or sets the DirectionsUIEventManager object.

Heading

double

No

Gets or sets the directional heading of the map. The heading is represented in geometric degrees with 0 or 360 = North, 90 = East, 180 = South, and 270 = West. You can set the heading by using the SetHeading method.

HomeRegion

String

Yes

Gets or sets the home region of the map.

IsTransitDirectionsEnable

bool

No

Gets whether transit directions are enabled.

LogoPosition

MapForegroundPosition

Yes

Gets or sets the location of the Bing Maps logo.

MapType

MapType

No

Gets or sets the map type, or style.

MaxZoomLevel

double

No

Gets the maximum zoom level for the map.

MetersPerPixel

double

No

Gets the current scale in meters per pixel of the center of the current map view.

MinZoomLevel

double

No

Gets the minimum zoom level for the map.

PreloadArea

MapViewPreloadArea

No

Gets or sets how much map data beyond the current view to preload. On clients with limited bandwidth, this should be set to None.

RotationEnabled

bool

No

Gets whether map view rotation is enabled.

ScaleBarPosition

MapForegroundPosition

Yes

Gets or sets the location of the scale bar.

SearchManager

SearchManager

No

Gets the search manager for the map.

ShapeLayers

MapShapeLayerCollection

No

Gets a collection of the map’s shape layers.

ShowBreadcrumb

bool

Yes

Gets or sets whether to show a breadcrumb control. The breadcrumb control shows the current center location’s geography hierarchy. For example, if the location center is Seattle, the breadcrumb control displays “World, United States, WA”.

The default value is false.

ShowBuildings

bool

Yes

Gets or sets whether to display building footprints.

The default value is true.

ShowNavigationBar

bool

Yes

Gets or sets whether to display map navigation controls.

The default value is true.

ShowScaleBar

bool

Yes

Gets or sets whether the scale bar is visible.

The default value is true

ShowTraffic

bool

Yes

Gets or sets whether to display traffic on the map.

The default value is false.

SuppressNetworkRequests

bool

Yes

Gets or sets whether to suppress network requests.

The default value is false.

TargetBounds

LocationRect

No

Gets the rectangle that defines the boundaries of the view to which the map is navigating.

TargetCenter

Location

No

Gets the location of the center of the view to which the map is navigating.

TargetHeading

double

No

Gets the directional heading of the view to which the map is navigating.

TargetZoomLevel

double

No

Gets the zoom level of the view to which the map is navigating.

TileLayers

MapTileLayerCollection

No

Gets a collection of the map’s tile layers.

TrafficIncidentPushpinOptions

TrafficIncidentPushpinOptions

No

Get the options to use for the pushpin that identifies traffic incidents.

TrafficManager

TrafficManager

No

Gets the traffic manager for the map.

VenueManager

VenueManager

No

Gets the venue manager for the map.

ViewRestriction

MapViewRestriction

No

Gets or sets the restrictions for changing the map view.

The default value is ZoomOutToWholeWorld.

ZoomLevel

double

No

Gets or sets the zoom level of the map. For the range of zoom levels, see the MinZoomLevel and MaxZoomLevel property values.

Public Methods

Name Definition Return Type Description

Dispose

Dispose()

None

Releases all resources associated with the map.

GetCopyrightAsync

GetCopyrightAsync()

IAsyncOperation<String>

Begins an asynchronous operation to get the copyright string for the current view. The copyright string contains one or more lines of text separated by a carriage return and line feed.

GetSessionIdAsync

GetSessionIdAsync()

IAsyncOperation<String>

Begins an asynchronous operation to get the session ID.

SetHeading

SetHeading(double heading)

None

Sets the directional heading of the map. The heading is represented in geometric degrees with 0 or 360 = North, 90 = East, 180 = South, and 270 = West.

Make sure the RotateEnabled is set to true before trying to change the map heading.

SetHeading

SetHeading(double heading, System.TimeSpan animationDuration)

None

Sets the directional heading of the map as well as the animation duration. If you do not want the view change to animate, set the animation duration to MapAnimationDuration.None.

Make sure the RotateEnabled is set to true before trying to change the map heading.

SetView

SetView( Location center)

None

Sets the map view using the specified center location. The view change will be animated.

SetView

SetView( Location center, double zoomLevel)

None

Sets the map view using the specified center location and zoom level. The view change will be animated.

SetView

SetView( Location center, double zoomLevel, double heading)

None

Sets the map view using the specified center location, zoom level, and heading. The view change will be animated.

SetView

SetView( Location center, double zoomLevel, double heading, System.TimeSpan animationDuration)

None

Sets the map view using the specified center location, zoom level, heading, and animation time. If you do not want the view change to animate, set the animation duration to MapAnimationDuration.None.

SetView

SetView( Location center, double zoomLevel, System.TimeSpan animationDuration)

None

Sets the map view using the specified center location, zoom level, and animation duration. If you do not want the view change to animate, set the animation duration to MapAnimationDuration.None.

SetView

SetView( Location center, System.TimeSpan animationDuration)

None

Sets the map view using the specified center location, and specifies the animation duration. If you do not want the view change to animate, set the animation duration to MapAnimationDuration.None.

SetView

SetView( LocationRect rect)

None

Sets the map view using the specified geographical region.

SetView

SetView( LocationRect rect, System.TimeSpan animationDuration)

None

Sets the map view using the specified geographical region and animation duration. If you do not want the view change to animate, set the animation duration to MapAnimationDuration.None.

SetZoomLevel

SetZoomLevel(double newZoomLevel)

None

Sets the zoom level of the map view to the specified value.

SetZoomLevel

SetZoomLevel(double newZoomLevel, System.TimeSpan animationDuration)

None

Sets the zoom level of the map view and the animation time. If you do not want the view change to animate, set the animation duration to MapAnimationDuration.None.

SetZoomLevelAroundPoint

SetZoomLevelAroundPoint(double newZoomLevel, Point point, System.TimeSpan animationDuration)

None

Sets the zoom level of the map view to the specified value while maintaining the screen position of the given point. You can also specify an animation time for the view change. If you do not want the view change to animate, set the animation duration to MapAnimationDuration.None. If you want to use the default animation time, set the animation duration to MapAnimationDuration.Default.

TryLocationToPixel

TryLocationToPixel( Location location, Point point)

bool

Returns a bool indicating whether the specified location was successfully converted to a map screen pixel. This method will work on locations that are not currently in view and will return values outside of the visible map area in the range (0,0) to (ActualWidth,ActualHeight).

TryLocationsToPixels

TryLocationsToPixels( LocationCollection locationCollection, System.Collections.Generic.IList<Point> pointVector)

bool

Returns a bool indicating whether the specified locations were successfully converted to a map screen pixels. The pixels are provided for a single world map. If multiple world maps are displayed, the first location in the collection that is closest to the center of the map determines which world map to use. This method will work on locations that are not currently in view and will return values outside of the visible map area in the range (0,0) to (ActualWidth,ActualHeight).

TryPixelToLocation

TryPixelToLocation( Point point, Location location)

bool

Returns a bool indicating whether the specified point was successfully converted to a location. This method will work on locations that are not currently in view.

Events

Name Arguments Description

CopyrightChanged

CopyrightChangedEventArgs

Occurs when the copyright of the map changes.

LandmarkTapped

LandmarkTappedEventArgs

Occurs when a landmark is tapped.

MapStyleChanged

MapStyleChangedEventArgs

Occurs when the map style changes.

TargetViewChanged

TargetViewChangedEventArgs

Occurs when the view towards which the map is navigating changes.

TileDownloadCompleted

TileDownloadCompletedEventArgs

Occurs when all of the map tiles of the map view have downloaded.

TileServersAvailabilityChanged

TileServersAvailabilityChangedEventArgs

Occurs when the connection to the tile servers is lost or restored.

ViewChanged

ViewChangedEventArgs

Occurs when the map view changes. This event is raised for every frame of the map view change.

ViewChangeEnded

ViewChangeEndedEventArgs

Occurs when the map view is done changing.

ViewChangeStarted

ViewChangeStartedEventArgs

Occurs when the map view starts changing.

UIElement Events

The Map class uses the inherited UIElement events. Some UIElement events have been overridden by the Map class. For these events, which are listed below, use the override event.

Event Overrides

Use these events instead of the equivalent UIElement events.

Event Replaces UIElement Event Description

DoubleTappedOverride

DoubleTapped

Occurs when an otherwise unhandled DoubleTap interaction occurs over the hit test area of the map.

KeyDownOverride

KeyDown

Occurs when a keyboard key is pressed while the map has focus.

KeyUpOverride

KeyUp

Occurs when a keyboard key is released while the map has focus.

PointerCanceledOverride

PointerCanceled

Occurs when a pointer that made contact abnormally loses contact.

PointerCaptureLostOverride

PointerCaptureLost

Occurs when pointer capture previously held by the map moves to another element or elsewhere.

PointerEnteredOverride

PointerEntered

Occurs when a pointer enters the hit test area of the map.

PointerExitedOverride

PointerExited

Occurs when a pointer leaves the hit test area of the map.

PointerMovedOverride

PointerMoved

Occurs when a pointer moves while the pointer remains within the hit test area of the map.

PointerPressedOverride

PointerPressed

Occurs when the pointer device initiates a Press action within the map.

PointerReleasedOverride

PointerReleased

Occurs when the pointer device that previously initiated a Press action is released, while within the map.

PointerWheelChangedOverride

PointerWheelChanged

Occurs when the delta value of a pointer wheel changes.

TappedOverride

Tapped

Occurs when an otherwise unhandled Tap interaction occurs over the hit test area of the map.

Remarks

Rotation, Animation and Heading

You can rotate the map by setting the Heading property with the SetHeading method. To set the heading, the MapType must be set to Birdseye and the ZoomLevel must be 9.5 or greater. It is best practice to use the RotationEnabled property to determine if you can rotate the map.

Heading is animated separately from the center and zoom level. Therefore, you can set the center and zoom level without interrupting an animated rotation.

Code Examples

Add a map to your application using XAML, specifying other map properties as well. Note that you must set the Credentials property to your Bing Maps Key.

<Page
    x:Class="Application1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Application1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:bm="using:Bing.Maps"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
      <bm:Map credentials="INSERT_YOUR_BING_MAPS_KEY" x:Name="myMap" MapType="Aerial" ZoomLevel="12">
        <bm:Map.Center>
        <bm:Location Latitude="46.227480" Longitude="-122.192955" />
        </bm:Map.Center>
      </bm:Map>
    </Grid>
</Page>

Set the Center point, ZoomLevel and MapType properties in code-behind.


myMap.Center = new Location(46.227480,-122.192955);
myMap.ZoomLevel = 12;
myMap.MapType = MapType.Aerial;

Set the map view by specifying a center point and zoom level. By default, the map transition is animated and the default animation time is used.

map.SetView(new Location(34.2162, -119.038), 12);

Set the map view without animation.

map.SetView(new Location(34.2162, -119.038), 12, MapAnimationDuration.None);

Set the map view and show traffic.

map.SetView(new Location(47.590482877750517, -122.27287683887229), 10);
map.ShowTraffic = true;

Rotate the map clockwise by 90 degrees by setting the heading. Make sure the RotationEnabled property is set to true before rotating the map. The animation time is set to the default value.

if (map.RotationEnabled) {
    map.SetHeading(map.Heading + 90, MapAnimationDuration.Default);
}

Get the copyright string for the current map view.

string copyright = await map.GetCopyrightAsync();
Show:
© 2014 Microsoft