Export (0) Print
Expand All

MapLayer class

Bing

Represents a map layer, which can contain elements positioned on the map. Map layers can be nested. This class inherits from Panel.

Constructor

Definition Description

MapLayer()

Initializes a new instance of the MapLayer class.

Static Properties

Name Type Description

PositionAnchorProperty

DependencyProperty

Gets the PositionAnchor dependency property.

PositionProperty

DependencyProperty

Gets the Position dependency property.

Static Methods

Name Definition Return Type Description

GetPosition

GetPosition( DependencyObject dependencyObject)

Location

Returns the position of a dependency object. This value is used to position a UIElement when it is a child of a Map or a MapLayer within a Map.

GetPositionAnchor

GetPositionAnchor( DependencyObject dependencyObject)

Point

Returns the position anchor of a dependency object.

SetPosition

SetPosition( DependencyObject dependencyObject, Location location)

None

Sets the position of a specified dependency object. This value is used to position a UIElement that is a child of a Map or a MapLayer within a Map.

SetPositionAnchor

SetPositionAnchor( DependencyObject dependencyObject, Point positionAnchor)

None

Sets the position anchor of a dependency object. This attached property is then used to position the element in a Map or MapLayer that is a child of a Map. The position anchor defaults to 0,0 which means the element will have its top-left position aligned with the Position value. For a round pushpin this should be set to (Width / 2, Height / 2) to center the element over its Position.

Code Examples

Add an image that is anchored to the map layer at the top left corner ((0,0) offset). The image is added directly to the map.

// Adds an image anchored at the top left.
Image image = new Image();
image.Source = new BitmapImage(new Uri(BaseUri,"Logo.png"));
image.Width = 20;
image.Height = 20;
MapLayer.SetPosition(image, new Location(44.092, -107.93));map.Children.Add(image);

Add an image that is anchored to the map layer at the top left corner ((0,0) offset). The image is added to a map layer, and then the map layer is added to the map.

// Adds an image anchored at the top left.
Image image = new Image();
image.Source = new BitmapImage(new Uri(BaseUri,"Logo.png"));
image.Width = 20;
image.Height = 20;
MapLayer.SetPosition(image, new Location(44.092, -107.93));
MapLayer layer = new MapLayer();
layer.Children.Add(image);
map.Children.Add(layer);

Add an image that is anchored to the specified location on the map layer by the image’s bottom right corner. Because the image has a dimension of 20 by 20, the bottom right corner is defined by the offset coordinate Point(20,20).

// Adds an image anchored at the bottom right.
Image image = new Image();
image.Source = new BitmapImage(new Uri(BaseUri,"Logo.png"));
image.Width = 20;
image.Height = 20;
MapLayer.SetPosition(image, new Location(44.092, -107.93));
MapLayer.SetPositionAnchor(image, new Point(20, 20));
map.Children.Add(image);

Add an image that is positioned relative to the greater Canvas and not the map layer.

// Adds an absolutely positioned image
Image image = new Image();
image.Source = new BitmapImage(new Uri(BaseUri,"Logo.png"));
image.Width = 20;
image.Height = 20;
Canvas.SetLeft(image, 100);
Canvas.SetTop(image, 10);
map.Children.Add(image);

Use XAML and the PositionAnchor and Position properties to add a button that is centered at the geographical coordinates (0,0).

<bm:Map x:Name="map" Credentials="INSERT_YOUR_BING_MAPS_KEY">
  <!-- Add a button centered at latlong 0,0 -->
  <Button Width="60" Height="40" Content="Foo" bm:MapLayer.PositionAnchor="30,20">
    <bm:MapLayer.Position>
     <bm:Location Latitude="0" Longitude="0" />
    </bm:MapLayer.Position>
  </Button>
</bm:Map>

Show:
© 2015 Microsoft