2

I'm placing multiple MapPolygons on a MapControl. The stroke for the MapPolygons do not set correctly. The stroke color for all polygons regardless of what layer they reside in binds to the polygon with the highest Z-index. I created an example using the UWP MapControl example from Microsoft: https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi See "Add a shape" section.

I tried placing each polygon in a separate layer but it gives similar results.

It is worth noting that the Polygon FillColor parameter is unaffected only the stroke color and thickness.

XAML

 <my:MapControl HorizontalAlignment="Left" x:Name="mapControl" MapServiceToken="..." Width="1650" Height="800" />

   public BlankPage1()
    {
        this.InitializeComponent();
        BasicGeoposition cityPosition = new BasicGeoposition() { Latitude = 34.8, Longitude = -116, Altitude = 0 };
        Emitter_Position = new Geopoint(cityPosition);

        mapControl.Center = Emitter_Position;
        mapControl.ZoomLevel = 9;
        mapControl.LandmarksVisible = true;
        test_polygons();
    }

    public void test_polygons()
    {
        double centerLatitude = Emitter_Position.Position.Latitude;
        double centerLongitude = Emitter_Position.Position.Longitude;
        var MyHighlights = new List<MapElement>();
        var mapPolygon = new MapPolygon
        {
            Path = new Geopath(new List<BasicGeoposition> {
                new BasicGeoposition() {Latitude=centerLatitude+0.1, Longitude=centerLongitude-0.1 },
                new BasicGeoposition() {Latitude=centerLatitude-0.1, Longitude=centerLongitude-0.1 },
                new BasicGeoposition() {Latitude=centerLatitude-0.1, Longitude=centerLongitude+0.1 },
                new BasicGeoposition() {Latitude=centerLatitude+0.1, Longitude=centerLongitude+0.1 },
            }),
            ZIndex = 2,
            FillColor = Colors.Red,
            StrokeColor = Colors.Blue,
            StrokeThickness = 3,
            StrokeDashed = false,
        };

        var mapPolygon2 = new MapPolygon
        {
            Path = new Geopath(new List<BasicGeoposition> {
                new BasicGeoposition() {Latitude=centerLatitude+0.2, Longitude=centerLongitude-0.2 },
                new BasicGeoposition() {Latitude=centerLatitude-0.2, Longitude=centerLongitude-0.2 },
                new BasicGeoposition() {Latitude=centerLatitude-0.2, Longitude=centerLongitude+0.2 },
                new BasicGeoposition() {Latitude=centerLatitude+0.2, Longitude=centerLongitude+0.2 },
            }),
            ZIndex = 1,
            FillColor = Colors.Green,
            StrokeColor = Colors.Yellow,
            StrokeThickness = 3,
            StrokeDashed = false,
        };

        MyHighlights.Add(mapPolygon);
        MyHighlights.Add(mapPolygon2);
        var HighlightsLayer = new MapElementsLayer
        {
            ZIndex = 1,
            MapElements = MyHighlights
        };
        Result_Map.Layers.Add(HighlightsLayer);

    }

The stroke color for mapPolygon2 shows as blue rather than yellow. If you enter image description hereflip the Zindex for the mapPolygons than the stroke for both polygons will be yellow. So what's the trick to get the stroke to set correctly when displaying multiple polygons?

Jason Pratt
  • 121
  • 4
  • 1
    When I used your code, it worked well, the stroke color for mapPolygon2 shows yellow. So can you provide a simple sample that can be reproduced? In addition, if you follow the [official sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MapControl) to add a single mapPolygon contains yellow stroke color, will the same issue occur? – Faywang - MSFT Oct 02 '19 at 14:50
  • If I add a single polygon the stroke displays correctly. What build version are you using, currently I am set to – Jason Pratt Oct 02 '19 at 15:32
  • 1
    Window10, version 1903 and I'm using vs2019, build 18362. – Faywang - MSFT Oct 02 '19 at 15:46
  • I edited my original question to show the xaml and how Im calling the test method. There are no other components on the page other than the map control. Im targeting a min version of 16299. I wonder if this is the issue. – Jason Pratt Oct 02 '19 at 16:02
  • I created a new solution, targeting build 16299. The solution has a single page with a single map control and I got the same results. – Jason Pratt Oct 02 '19 at 16:17
  • Window 10, Ver 1709 – Jason Pratt Oct 02 '19 at 16:21
  • I posted this question on a Microsoft discussion board and here is the reply : "This was a known issue with earlier versions of Windows, but the latest versions should behave as expected." Unfortunately I'm at the mercy of my IT department concerning Window's updates and must use V.1709 so I can't verify. Given that @Faywang ran the code successfully, I'm assuming that I'm dealing with a known bug. – Jason Pratt Oct 02 '19 at 23:30
  • 1
    The best way to do this is to use the latest version. Can you apply to the IT department to use the latest version? – Faywang - MSFT Oct 03 '19 at 12:42

1 Answers1

2

This won't be impacted by the version of the OS you're targeting, but by the version of the OS you're running on. This was a known issue in OS versions prior to 1809, so it's been fixed for about one year. Updating to a more recent build of the OS should solve your issue. A recommended workaround if you can't update the OS would be to draw the polygon without a border, and then draw the border as a polyline in a separate call.

Duncan Lawler
  • 1,772
  • 8
  • 13
  • I will accept this as an answer, For this being a known issue, I didn't find a single question concerning this issue on stackoverflow, Microsoft websites, Google search,etc. So as a developer how do I avoid wasting hours of time troubleshooting a known issue that is poorly documented? – Jason Pratt Oct 05 '19 at 03:51
  • 2
    Drawing polygons is not a commonly used map control feature, and polygons with borders are even more rarely used, so that's probably why there was no public posting about this bug. In this case it was found and fixed through internal testing and the full list of bugs fixed with each release isn't made public typically. If you encounter an issue where the control isn't behaving per documentation, it's best to post here or on the MSDN developer forums, or contact your support representative if you have an enterprise account. It's usually looked into fairly quickly. – Duncan Lawler Oct 07 '19 at 20:34
  • Pls take a look at my question too https://stackoverflow.com/questions/68950727/where-is-uwp-mapcontrol-antialiasing-property – NoWar Aug 27 '21 at 09:13