MapPolypoint implementation

This commit is contained in:
ClemensFischer 2024-07-16 10:41:44 +02:00
parent fa508f51e7
commit b573bafb48
2 changed files with 46 additions and 21 deletions

View file

@ -2,6 +2,7 @@
// Copyright © 2024 Clemens Fischer // Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
@ -60,6 +61,13 @@ namespace MapControl
AddPolylinePoints(pathFigures, locations, longitudeOffset, closed); AddPolylinePoints(pathFigures, locations, longitudeOffset, closed);
} }
if (pathFigures.Count == 0)
{
// Avalonia Shape seems to ignore PathGeometry with empty Figures collection
pathFigures.Add(new PathFigure { StartPoint = new Point(-1000, -1000) });
}
((PathGeometry)Data).Figures = pathFigures; ((PathGeometry)Data).Figures = pathFigures;
InvalidateGeometry(); InvalidateGeometry();
@ -74,15 +82,34 @@ namespace MapControl
if (points.Any()) if (points.Any())
{ {
var figure = new PathFigure var startPoint = points.First();
var polylineSegment = new PolyLineSegment(points.Skip(1));
var minX = startPoint.X;
var maxX = startPoint.X;
var minY = startPoint.Y;
var maxY = startPoint.Y;
foreach (var point in polylineSegment.Points)
{ {
StartPoint = points.First(), minX = Math.Min(minX, point.X);
maxX = Math.Max(maxX, point.X);
minY = Math.Min(minY, point.Y);
maxY = Math.Max(maxY, point.Y);
}
if (maxX >= 0 && minX <= ParentMap.ActualWidth &&
maxY >= 0 && minY <= ParentMap.ActualHeight)
{
var pathFigure = new PathFigure
{
StartPoint = startPoint,
IsClosed = closed, IsClosed = closed,
IsFilled = true IsFilled = true
}; };
figure.Segments.Add(new PolyLineSegment(points.Skip(1))); pathFigure.Segments.Add(polylineSegment);
pathFigures.Add(figure); pathFigures.Add(pathFigure);
}
} }
} }
} }

View file

@ -80,36 +80,34 @@ namespace MapControl
if (points.Any()) if (points.Any())
{ {
var startPoint = points.First(); var startPoint = points.First();
var polylineSegment = new PolyLineSegment();
var minX = startPoint.X; var minX = startPoint.X;
var maxX = startPoint.X; var maxX = startPoint.X;
var minY = startPoint.Y; var minY = startPoint.Y;
var maxY = startPoint.Y; var maxY = startPoint.Y;
var figure = new PathFigure foreach (var point in points.Skip(1))
{
polylineSegment.Points.Add(point);
minX = Math.Min(minX, point.X);
maxX = Math.Max(maxX, point.X);
minY = Math.Min(minY, point.Y);
maxY = Math.Max(maxY, point.Y);
}
if (maxX >= 0 && minX <= ParentMap.ActualWidth &&
maxY >= 0 && minY <= ParentMap.ActualHeight)
{
var pathFigure = new PathFigure
{ {
StartPoint = startPoint, StartPoint = startPoint,
IsClosed = closed, IsClosed = closed,
IsFilled = true IsFilled = true
}; };
var polyline = new PolyLineSegment(); pathFigure.Segments.Add(polylineSegment);
pathFigures.Add(pathFigure);
foreach (var point in points.Skip(1))
{
minX = Math.Min(minX, point.X);
maxX = Math.Max(maxX, point.X);
minY = Math.Min(minY, point.Y);
maxY = Math.Max(maxY, point.Y);
polyline.Points.Add(point);
} }
if (maxX >= 0 && minX <= ParentMap.ActualWidth &&
maxY >= 0 && minY <= ParentMap.ActualHeight)
{
figure.Segments.Add(polyline);
}
pathFigures.Add(figure);
} }
} }
} }