Avalonia MapGraticule

This commit is contained in:
ClemensFischer 2024-05-26 20:32:29 +02:00
parent 9980733c37
commit 8bb7dc3eb3
13 changed files with 247 additions and 495 deletions

View file

@ -6,31 +6,66 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MapControl
{
public partial class MapGraticule
public partial class MapGraticule : Control, IMapElement
{
static MapGraticule()
public static readonly DependencyProperty StrokeThicknessProperty =
DependencyPropertyHelper.Register<MapGraticule, double>(nameof(StrokeThickness), 0.5);
public double StrokeThickness
{
StrokeThicknessProperty.OverrideMetadata(typeof(MapGraticule), new FrameworkPropertyMetadata(0.5));
get => (double)GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
protected override void OnViewportChanged(ViewportChangedEventArgs e)
private MapBase parentMap;
/// <summary>
/// Implements IMapElement.ParentMap.
/// </summary>
public MapBase ParentMap
{
get => parentMap;
set
{
if (parentMap != null)
{
parentMap.ViewportChanged -= OnViewportChanged;
}
parentMap = value;
if (parentMap != null)
{
parentMap.ViewportChanged += OnViewportChanged;
}
}
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
InvalidateVisual();
}
protected override void OnRender(DrawingContext drawingContext)
{
if (ParentMap != null)
if (parentMap != null)
{
var pathGeometry = new PathGeometry();
var labels = DrawGraticule(pathGeometry.Figures);
drawingContext.DrawGeometry(null, CreatePen(), pathGeometry);
var pen = new Pen
{
Brush = Foreground,
Thickness = StrokeThickness,
};
drawingContext.DrawGeometry(null, pen, pathGeometry);
if (labels.Count > 0)
{