Map Class
Represents a map. This class inherits from the Control class.
Constructor
| Definition | Description |
|---|---|
|
|
Initializes a new instance of the Map class. |
Properties
| Name | Type | Databindable | Description |
|---|---|---|---|
|
Bounds |
No |
Gets a rectangle that defines the map view. |
|
|
Center |
No |
Gets or sets the location of the center of the map. |
|
|
Children |
No |
Gets any UI elements that are children of the map control element. |
|
|
CopyrightPosition |
No |
Gets or sets the position of the map copyright string. |
|
|
Culture |
String |
Yes |
Gets or sets the culture code to use. |
|
Credentials |
String |
Yes |
Gets or sets the map credentials used to authenticate the map. |
|
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. |
|
LogoPosition |
Yes |
Gets or sets the location of the Bing Maps logo. |
|
|
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 |
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 |
No |
Gets or sets the location of the scale bar. |
|
|
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. |
|
ShapeLayers |
No |
Gets a collection of the map’s shape layers. |
|
|
ShowBreadcrumb |
bool |
No |
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. |
|
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 |
No |
Gets the rectangle that defines the boundaries of the view to which the map is navigating. |
|
|
TargetCenter |
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 |
No |
Gets a collection of the map’s tile layers. |
|
|
VenueManager |
No |
Gets the venue manager for the map. |
|
|
ViewRestriction |
No |
Gets or sets the restrictions for changing the map view. The default value is |
|
|
ZoomLevel |
double |
No |
Gets or sets the zoom level of the map. |
Public Methods
| Name | Definition | Return Type | Description |
|---|---|---|---|
|
Dispose |
|
None |
Releases all resources associated with the map. |
|
GetSessionIdAsync |
|
IAsyncOperation<String> |
Begins an asynchronous operation to get the session ID. |
|
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. |
|
SetHeading |
|
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 |
|
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 |
|
None |
Sets the map view using the specified center location. The view change will be animated. |
|
SetView |
|
None |
Sets the map view using the specified center location and zoom level. The view change will be animated. |
|
SetView |
|
None |
Sets the map view using the specified center location, zoom level, and heading. The view change will be animated. |
|
SetView |
|
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 |
|
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 |
|
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 |
|
None |
Sets the map view using the specified geographical region. |
|
SetView |
|
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 |
|
None |
Sets the zoom level of the map view to the specified value. |
|
SetZoomLevel |
|
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 |
|
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 |
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 |
|
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 |
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 |
Occurs when the copyright of the map changes. |
|
|
MapStyleChanged |
Occurs when the map style changes. |
|
|
PropertyChanged |
Occurs when a map property changes. |
|
|
TargetViewChanged |
Occurs when the view towards which the map is navigating changes. |
|
|
TileDownloadCompleted |
Occurs when all of the map tiles of the map view have downloaded. |
|
|
TileServersAvailabilityChanged |
Occurs when the connection to the tile servers is lost or restored. |
|
|
ViewChanged |
Occurs when the map view changes. This event is raised for every frame of the map view change. |
|
|
ViewChangeEnded |
Occurs when the map view is done changing. |
|
|
ViewChangeStarted |
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 that 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. 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();