Removed common MapOverlay part

This commit is contained in:
ClemensFischer 2024-05-26 14:15:02 +02:00
parent acdfc1861f
commit bbd4f6d6aa
7 changed files with 261 additions and 140 deletions

View file

@ -5,12 +5,11 @@
using Avalonia.Collections;
using Avalonia.Controls.Documents;
using Avalonia.Controls.Shapes;
using Avalonia.Data;
using Avalonia.Media;
namespace MapControl
{
public partial class MapOverlay
public class MapOverlay : MapPanel
{
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
DependencyPropertyHelper.AddOwner<MapOverlay, FontFamily>(TextElement.FontFamilyProperty);
@ -51,14 +50,82 @@ namespace MapControl
public static readonly StyledProperty<double> StrokeMiterLimitProperty =
DependencyPropertyHelper.Register<MapOverlay, double>(nameof(StrokeMiterLimit));
protected override void OnInitialized()
public FontFamily FontFamily
{
base.OnInitialized();
get => GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
if (Stroke == null)
{
this.SetBinding(StrokeProperty, this.CreateBinding(nameof(Foreground)));
}
public double FontSize
{
get => GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public FontStyle FontStyle
{
get => GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public FontStretch FontStretch
{
get => GetValue(FontStretchProperty);
set => SetValue(FontStretchProperty, value);
}
public FontWeight FontWeight
{
get => GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public IBrush Foreground
{
get => GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public IBrush Stroke
{
get => GetValue(StrokeProperty);
set => SetValue(StrokeProperty, value);
}
public double StrokeThickness
{
get => GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
public AvaloniaList<double> StrokeDashArray
{
get => GetValue(StrokeDashArrayProperty);
set => SetValue(StrokeDashArrayProperty, value);
}
public double StrokeDashOffset
{
get => GetValue(StrokeDashOffsetProperty);
set => SetValue(StrokeDashOffsetProperty, value);
}
public PenLineCap StrokeLineCap
{
get => GetValue(StrokeLineCapProperty);
set => SetValue(StrokeLineCapProperty, value);
}
public PenLineJoin StrokeLineJoin
{
get => GetValue(StrokeLineJoinProperty);
set => SetValue(StrokeLineJoinProperty, value);
}
public double StrokeMiterLimit
{
get => (double)GetValue(StrokeMiterLimitProperty);
set => SetValue(StrokeMiterLimitProperty, value);
}
public Pen CreatePen()
@ -73,5 +140,15 @@ namespace MapControl
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset)
};
}
protected override void OnInitialized()
{
base.OnInitialized();
if (Stroke == null)
{
this.SetBinding(StrokeProperty, this.CreateBinding(nameof(Foreground)));
}
}
}
}

View file

@ -1,104 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
#if WPF
using System.Windows;
using System.Windows.Media;
#elif UWP
using Windows.UI.Text;
using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI.Xaml.Media;
using Windows.UI.Text;
#elif AVALONIA
using Avalonia.Media;
using DoubleCollection = System.Collections.Generic.IEnumerable<double>;
#endif
namespace MapControl
{
/// <summary>
/// Base class for map overlays with background, foreground, stroke and font properties.
/// </summary>
public partial class MapOverlay : MapPanel
{
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public FontStretch FontStretch
{
get => (FontStretch)GetValue(FontStretchProperty);
set => SetValue(FontStretchProperty, value);
}
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public Brush Stroke
{
get => (Brush)GetValue(StrokeProperty);
set => SetValue(StrokeProperty, value);
}
public double StrokeThickness
{
get => (double)GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
public DoubleCollection StrokeDashArray
{
get => (DoubleCollection)GetValue(StrokeDashArrayProperty);
set => SetValue(StrokeDashArrayProperty, value);
}
public double StrokeDashOffset
{
get => (double)GetValue(StrokeDashOffsetProperty);
set => SetValue(StrokeDashOffsetProperty, value);
}
public PenLineCap StrokeLineCap
{
get => (PenLineCap)GetValue(StrokeLineCapProperty);
set => SetValue(StrokeLineCapProperty, value);
}
public PenLineJoin StrokeLineJoin
{
get => (PenLineJoin)GetValue(StrokeLineJoinProperty);
set => SetValue(StrokeLineJoinProperty, value);
}
public double StrokeMiterLimit
{
get => (double)GetValue(StrokeMiterLimitProperty);
set => SetValue(StrokeMiterLimitProperty, value);
}
}
}

View file

@ -119,9 +119,6 @@
<Compile Include="..\Shared\MapItemsControl.cs">
<Link>MapItemsControl.cs</Link>
</Compile>
<Compile Include="..\Shared\MapOverlay.cs">
<Link>MapOverlay.cs</Link>
</Compile>
<Compile Include="..\Shared\MapPanel.cs">
<Link>MapPanel.cs</Link>
</Compile>

View file

@ -17,8 +17,6 @@ namespace MapControl
StrokeThicknessProperty.OverrideMetadata(typeof(MapGraticule), new FrameworkPropertyMetadata(0.5));
}
private readonly PathGeometry pathGeometry = new PathGeometry();
protected override void OnViewportChanged(ViewportChangedEventArgs e)
{
InvalidateVisual();

View file

@ -4,14 +4,13 @@
using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MapControl
{
public partial class MapOverlay
public class MapOverlay : MapPanel
{
public static readonly DependencyProperty FontFamilyProperty =
DependencyPropertyHelper.AddOwner<MapOverlay, FontFamily>(TextElement.FontFamilyProperty);
@ -52,14 +51,82 @@ namespace MapControl
public static readonly DependencyProperty StrokeMiterLimitProperty =
DependencyPropertyHelper.AddOwner<MapOverlay, double>(Shape.StrokeMiterLimitProperty);
protected override void OnInitialized(EventArgs e)
public FontFamily FontFamily
{
base.OnInitialized(e);
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
if (Stroke == null)
{
SetBinding(StrokeProperty, this.CreateBinding(nameof(Foreground)));
}
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public FontStretch FontStretch
{
get => (FontStretch)GetValue(FontStretchProperty);
set => SetValue(FontStretchProperty, value);
}
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public Brush Stroke
{
get => (Brush)GetValue(StrokeProperty);
set => SetValue(StrokeProperty, value);
}
public double StrokeThickness
{
get => (double)GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
public DoubleCollection StrokeDashArray
{
get => (DoubleCollection)GetValue(StrokeDashArrayProperty);
set => SetValue(StrokeDashArrayProperty, value);
}
public double StrokeDashOffset
{
get => (double)GetValue(StrokeDashOffsetProperty);
set => SetValue(StrokeDashOffsetProperty, value);
}
public PenLineCap StrokeLineCap
{
get => (PenLineCap)GetValue(StrokeLineCapProperty);
set => SetValue(StrokeLineCapProperty, value);
}
public PenLineJoin StrokeLineJoin
{
get => (PenLineJoin)GetValue(StrokeLineJoinProperty);
set => SetValue(StrokeLineJoinProperty, value);
}
public double StrokeMiterLimit
{
get => (double)GetValue(StrokeMiterLimitProperty);
set => SetValue(StrokeMiterLimitProperty, value);
}
public Pen CreatePen()
@ -76,5 +143,15 @@ namespace MapControl
DashStyle = new DashStyle(StrokeDashArray, StrokeDashOffset)
};
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
if (Stroke == null)
{
SetBinding(StrokeProperty, this.CreateBinding(nameof(Foreground)));
}
}
}
}

View file

@ -5,18 +5,16 @@
using Windows.UI.Text;
#if UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
#else
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
#endif
namespace MapControl
{
public partial class MapOverlay
public class MapOverlay : MapPanel
{
public static readonly DependencyProperty FontFamilyProperty =
DependencyPropertyHelper.Register<MapOverlay, FontFamily>(nameof(FontFamily));
@ -57,6 +55,84 @@ namespace MapControl
public static readonly DependencyProperty StrokeMiterLimitProperty =
DependencyPropertyHelper.Register<MapOverlay, double>(nameof(StrokeMiterLimit), 1d);
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public FontStretch FontStretch
{
get => (FontStretch)GetValue(FontStretchProperty);
set => SetValue(FontStretchProperty, value);
}
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public Brush Stroke
{
get => (Brush)GetValue(StrokeProperty);
set => SetValue(StrokeProperty, value);
}
public double StrokeThickness
{
get => (double)GetValue(StrokeThicknessProperty);
set => SetValue(StrokeThicknessProperty, value);
}
public DoubleCollection StrokeDashArray
{
get => (DoubleCollection)GetValue(StrokeDashArrayProperty);
set => SetValue(StrokeDashArrayProperty, value);
}
public double StrokeDashOffset
{
get => (double)GetValue(StrokeDashOffsetProperty);
set => SetValue(StrokeDashOffsetProperty, value);
}
public PenLineCap StrokeLineCap
{
get => (PenLineCap)GetValue(StrokeLineCapProperty);
set => SetValue(StrokeLineCapProperty, value);
}
public PenLineJoin StrokeLineJoin
{
get => (PenLineJoin)GetValue(StrokeLineJoinProperty);
set => SetValue(StrokeLineJoinProperty, value);
}
public double StrokeMiterLimit
{
get => (double)GetValue(StrokeMiterLimitProperty);
set => SetValue(StrokeMiterLimitProperty, value);
}
protected override void SetParentMap(MapBase map)
{
if (map != null)

View file

@ -80,13 +80,6 @@ namespace MapControl
if (closed)
{
var segment = new PolyLineSegment();
foreach (var point in points.Skip(1))
{
segment.Points.Add(point);
}
var figure = new PathFigure
{
StartPoint = points.First(),
@ -94,7 +87,14 @@ namespace MapControl
IsFilled = true
};
figure.Segments.Add(segment);
var polyline = new PolyLineSegment();
foreach (var point in points.Skip(1))
{
polyline.Points.Add(point);
}
figure.Segments.Add(polyline);
pathFigures.Add(figure);
}
else
@ -108,7 +108,7 @@ namespace MapControl
var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height);
PathFigure figure = null;
PolyLineSegment segment = null;
PolyLineSegment polyline = null;
for (int i = 1; i < pointList.Count; i++)
{
@ -127,12 +127,12 @@ namespace MapControl
IsFilled = true
};
segment = new PolyLineSegment();
figure.Segments.Add(segment);
polyline = new PolyLineSegment();
figure.Segments.Add(polyline);
pathFigures.Add(figure);
}
segment.Points.Add(p2);
polyline.Points.Add(p2);
}
if (!inside || p2 != pointList[i])