Drawing a polygon on several maps RRS feed

  • Question

  • Hello,

    I'm drawing a polygon on my map, in WPF. Everything's fine, but the problem is when i zoom out, i can see other maps, like if they're added after the principal and the polygon isn't drawn on those.

    My questions are : Is it possible to draw on several maps at the same time? And how to do it?



    Tuesday, March 3, 2015 10:44 AM


All replies

  • The additional maps are there for the "World Wrap" functionality which allows you to pan horizontal forever.  This is the 2D version of spinning a globe. It is technically possible to show the polygon across all the maps but it requires a lot more work and means that you will be showing a lot more data on the map which will hurt performance. For example, if you draw 100 polygons but three maps are in view it will render 300 polygons.

    If you really want to do this there are two options;

    1. Create a custom shape class that handles this. I have done this before to test it out. I had functional code but it really hurt performance.
    2. Turn the polygons into a tile layer. Tile layers are automatically spread across all maps.

    Tuesday, March 3, 2015 4:59 PM
  • I guess the second option is the one that i need, but it doesn't work for me. I took the exemple in the msdn page of "Adding shapes to the map". I modified it so it can do what i want, but it tells me that he can't load "Microsoft.Maps.MapControl.WPF.pdb". I've searched everywhere but can't find any references to this error.

    Here's the code:

    MapTileLayer layer = new MapTileLayer();

    MapPolygon polygon = new MapPolygon(); polygon.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue); polygon.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green); polygon.StrokeThickness = 5; polygon.Opacity = 0.7; polygon.Locations = new LocationCollection() { new Location(47.6424,-122.3219), new Location(47.8424,-122.1747), new Location(47.5814,-122.1747)}; layer.Children.Add(polygon); myMap.Children.Add(layer);

    • Edited by Grmax Wednesday, March 4, 2015 6:07 PM
    Wednesday, March 4, 2015 5:45 PM
  • That strange. A pdb file is from a debugger and shouldn't be available in the released version of the map control. Are you sure you have the WPF map control installed correctly?

    Wednesday, March 4, 2015 11:48 PM
  • Is adding map shapes to a tile layer's children valid?  I tried it real quick and got a null reference exception when it tried to draw.  I've only added map shapes directly to the Bing map's children before.
    • Proposed as answer by Ricky_Brundritt Thursday, March 5, 2015 7:34 PM
    • Unproposed as answer by Grmax Friday, March 6, 2015 5:54 PM
    • Marked as answer by Ricky_Brundritt Tuesday, April 7, 2015 6:55 PM
    Thursday, March 5, 2015 6:37 PM
  • Good point Zloth X. I didn't even see that. Polygons should be added to MapLayers, not MapTileLayers.

    Thursday, March 5, 2015 7:34 PM
  • No error with this, but it's not what i want. The polygon is drawn only on the principal map and not on the others.

    The reason i tried with MapTileLayer is because you mentioned it on your first comment, and it seemed like the best for my problem.

    So, is there another Layer that i'm not aware of?

    • Edited by Grmax Friday, March 6, 2015 6:00 PM
    Friday, March 6, 2015 5:51 PM
  • Friday, March 6, 2015 6:07 PM