Updated MapGraticule

This commit is contained in:
ClemensFischer 2025-06-10 09:13:48 +02:00
parent 8e8d414a46
commit ee136831e6
2 changed files with 12 additions and 7 deletions

View file

@ -107,7 +107,7 @@ namespace MapControl
labelFormat, hemisphere, seconds / 3600, seconds / 60 % 60, seconds % 60);
}
private void AddLabel(ICollection<Label> labels, Location location, Point position, double? rotation = null)
private void AddLabel(List<Label> labels, Location location, Point position, double? rotation = null)
{
if (position.X >= 0d && position.X <= ParentMap.ActualWidth &&
position.Y >= 0d && position.Y <= ParentMap.ActualHeight)
@ -135,7 +135,7 @@ namespace MapControl
}
}
private ICollection<Label> DrawGraticule(PathFigureCollection figures)
private List<Label> DrawGraticule(PathFigureCollection figures)
{
var labels = new List<Label>();
@ -155,7 +155,7 @@ namespace MapControl
return labels;
}
private void DrawCylindricalGraticule(PathFigureCollection figures, ICollection<Label> labels)
private void DrawCylindricalGraticule(PathFigureCollection figures, List<Label> labels)
{
var boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(0, 0, ParentMap.ActualWidth, ParentMap.ActualHeight));
var latLabelStart = Math.Ceiling(boundingBox.South / lineDistance) * lineDistance;
@ -195,7 +195,7 @@ namespace MapControl
}
}
private void DrawGraticule(PathFigureCollection figures, ICollection<Label> labels)
private void DrawGraticule(PathFigureCollection figures, List<Label> labels)
{
var minLat = 0d;
var maxLat = 0d;

View file

@ -28,8 +28,6 @@ namespace MapControl
public static readonly DependencyProperty FontSizeProperty =
DependencyPropertyHelper.Register<MapGraticule, double>(nameof(FontSize), 12d);
private readonly Path path = new Path { Data = new PathGeometry() };
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
@ -61,10 +59,12 @@ namespace MapControl
protected override void OnViewportChanged(ViewportChangedEventArgs e)
{
var labels = DrawGraticule(((PathGeometry)path.Data).Figures);
Path path;
if (Children.Count == 0)
{
path = new Path { Data = new PathGeometry() };
path.SetBinding(Shape.StrokeProperty,
new Binding { Source = this, Path = new PropertyPath(nameof(Foreground)) });
@ -73,7 +73,12 @@ namespace MapControl
Children.Add(path);
}
else
{
path = (Path)Children[0];
}
var labels = DrawGraticule(((PathGeometry)path.Data).Figures);
var childrenCount = 1;
foreach (var label in labels)