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 flip 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?