Updated MapGraticule

This commit is contained in:
ClemensFischer 2025-06-09 22:34:05 +02:00
parent 0696441a4e
commit 5a681d3580
4 changed files with 16 additions and 57 deletions

View file

@ -1,47 +1,15 @@
using Avalonia.Controls.Shapes;
using Avalonia.Controls.Primitives;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace MapControl
{
public partial class MapGraticule : Control, IMapElement
public partial class MapGraticule : TemplatedControl, IMapElement
{
public static readonly StyledProperty<Brush> ForegroundProperty =
DependencyPropertyHelper.AddOwner<MapGraticule, Brush>(TextElement.ForegroundProperty, null,
(graticule, oldValue, newValue) => graticule.InvalidateVisual());
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
DependencyPropertyHelper.AddOwner<MapGraticule, FontFamily>(TextElement.FontFamilyProperty);
public static readonly StyledProperty<double> FontSizeProperty =
DependencyPropertyHelper.AddOwner<MapGraticule, double>(TextElement.FontSizeProperty);
public static readonly StyledProperty<double> StrokeThicknessProperty =
DependencyPropertyHelper.AddOwner<MapGraticule, double>(Shape.StrokeThicknessProperty, 0.5);
public Brush Foreground
static MapGraticule()
{
get => GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public FontFamily FontFamily
{
get => GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
public double FontSize
{
get => GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public double StrokeThickness
{
get => GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
ForegroundProperty.Changed.AddClassHandler<MapGraticule, IBrush>((graticule, e) => graticule.InvalidateVisual());
}
private MapBase parentMap;
@ -91,7 +59,7 @@ namespace MapControl
if (labels.Count > 0)
{
var typeface = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Normal, FontStretch.Normal);
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
foreach (var label in labels)
{

View file

@ -40,11 +40,17 @@ namespace MapControl
private const double LineInterpolationResolution = 2d;
public static readonly DependencyProperty StrokeThicknessProperty =
DependencyPropertyHelper.Register<MapGraticule, double>(nameof(StrokeThickness), 0.5);
public static readonly DependencyProperty MinLineDistanceProperty =
DependencyPropertyHelper.Register<MapGraticule, double>(nameof(MinLineDistance), 150d);
private double lineDistance;
private string labelFormat;
public double StrokeThickness
{
get => (double)GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
/// <summary>
/// Minimum graticule line distance in pixels. The default value is 150.
@ -55,6 +61,9 @@ namespace MapControl
set => SetValue(MinLineDistanceProperty, value);
}
private double lineDistance;
private string labelFormat;
private void SetLineDistance()
{
var minDistance = MinLineDistance / PixelPerLongitudeDegree(ParentMap.Center);

View file

@ -9,15 +9,6 @@ namespace MapControl
{
public partial class MapGraticule : Control, IMapElement
{
public static readonly DependencyProperty StrokeThicknessProperty =
DependencyPropertyHelper.Register<MapGraticule, double>(nameof(StrokeThickness), 0.5);
public double StrokeThickness
{
get => (double)GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
private MapBase parentMap;
/// <summary>

View file

@ -28,9 +28,6 @@ namespace MapControl
public static readonly DependencyProperty FontSizeProperty =
DependencyPropertyHelper.Register<MapGraticule, double>(nameof(FontSize), 12d);
public static readonly DependencyProperty StrokeThicknessProperty =
DependencyPropertyHelper.Register<MapGraticule, double>(nameof(StrokeThickness), 0.5);
private readonly Path path = new Path { Data = new PathGeometry() };
public Brush Foreground
@ -51,12 +48,6 @@ namespace MapControl
set => SetValue(FontSizeProperty, value);
}
public double StrokeThickness
{
get => (double)GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
protected override void SetParentMap(MapBase map)
{
if (map != null && Foreground == null)