mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Avalonia MapGraticule
This commit is contained in:
parent
9980733c37
commit
8bb7dc3eb3
13 changed files with 247 additions and 495 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue