Search code examples
bing-maps

Bing maps polygon/polyline appears beneath image overlay


I´ve been following this post about using an image overlay for bing maps:

http://blogs.msdn.com/b/bingdevcenter/archive/2014/04/04/image-overlays-with-bing-maps-native.aspx

What I want to now is to be able to add polygons/polylines on top of this image. Lets say for example that we use the following code:

(From here: http://blogs.bing.com/maps/2014/01/23/make-clickable-shapes-in-the-native-bing-maps-control/)


private void MyMapLoaded(object sender, RoutedEventArgs e)
{
//Add a shape layer to the map
    shapeLayer = new MapShapeLayer();
    MyMap.ShapeLayers.Add(shapeLayer);

//Create mock data points
    var locs = new LocationCollection();

    locs.Add(new Location(coordinates that are over the image));
    locs.Add(new Location(coordinates that are over the image));
    locs.Add(new Location(coordinates that are over the image));

//Create test polygon
    var polygon = new MapPolygon();
    polygon.Locations = locs;
    polygon.FillColor = Colors.Red;


    shapeLayer.Shapes.Add(polygon);

    var locs2 = new LocationCollection();
    locs2.Add(new Location(20, 20));
    locs2.Add(new Location(40, 40));
    locs2.Add(new Location(50, 20));

//Create test polyline
    var polyline = new MapPolyline();
    polyline.Locations = locs2;
    polyline.Width = 5;
    polyline.Color = Colors.Blue;



//Add the shape to the map
    shapeLayer.Shapes.Add(polyline);
}

The problem is that the polygon/polyline will always appear beneath the image. ShapeLayer has a property for z-index but it does not help. Is there a way for my polygons to always be on top?


Solution

  • Not sure why you want to do this, but you won't be able to show a MapPolygon above a user control that is added as a child of the map. That said, you can create WPF Polygons and added them. What you could do is create a custom user control that combines the image overlay functionality with something like this: http://blogs.msdn.com/b/bingdevcenter/archive/2014/03/25/custom-shapes-in-windows-store-apps-c.aspx