Added MetricGrid

This commit is contained in:
ClemensFischer 2026-02-07 22:10:06 +01:00
parent 7857118712
commit 80252cbfd0
7 changed files with 292 additions and 184 deletions

View file

@ -6,16 +6,16 @@ using System.Windows.Media;
namespace MapControl
{
public partial class MapGraticule : FrameworkElement, IMapElement
public partial class MapGrid : FrameworkElement, IMapElement
{
public static readonly DependencyProperty ForegroundProperty =
DependencyPropertyHelper.AddOwner<MapGraticule, Brush>(TextElement.ForegroundProperty);
DependencyPropertyHelper.AddOwner<MapGrid, Brush>(TextElement.ForegroundProperty);
public static readonly DependencyProperty FontFamilyProperty =
DependencyPropertyHelper.AddOwner<MapGraticule, FontFamily>(TextElement.FontFamilyProperty);
DependencyPropertyHelper.AddOwner<MapGrid, FontFamily>(TextElement.FontFamilyProperty);
public static readonly DependencyProperty FontSizeProperty =
DependencyPropertyHelper.AddOwner<MapGraticule, double>(TextElement.FontSizeProperty, 12d);
DependencyPropertyHelper.AddOwner<MapGrid, double>(TextElement.FontSizeProperty, 12d);
/// <summary>
/// Implements IMapElement.ParentMap.
@ -40,6 +40,11 @@ namespace MapControl
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
OnViewportChanged(e);
}
protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
{
InvalidateVisual();
}
@ -56,7 +61,7 @@ namespace MapControl
Thickness = StrokeThickness,
};
DrawGraticule(pathGeometry.Figures, labels);
DrawGrid(pathGeometry.Figures, labels);
drawingContext.DrawGeometry(null, pen, pathGeometry);
@ -67,20 +72,21 @@ namespace MapControl
foreach (var label in labels)
{
var latText = new FormattedText(label.LatitudeText,
var text = new FormattedText(label.Text,
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip);
var lonText = new FormattedText(label.LongitudeText,
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip);
var x = label.X + StrokeThickness / 2d + 2d;
var y1 = label.Y - StrokeThickness / 2d - latText.Height;
var y2 = label.Y + StrokeThickness / 2d;
var y = label.Y - text.Height / 2d;
drawingContext.PushTransform(new RotateTransform(label.Rotation, label.X, label.Y));
drawingContext.DrawText(latText, new Point(x, y1));
drawingContext.DrawText(lonText, new Point(x, y2));
drawingContext.Pop();
if (label.Rotation != 0d)
{
drawingContext.PushTransform(new RotateTransform(label.Rotation, label.X, label.Y));
drawingContext.DrawText(text, new Point(x, y));
drawingContext.Pop();
}
else
{
drawingContext.DrawText(text, new Point(x, y));
}
}
}
}