diff --git a/MapControl/Avalonia/MapOverlay.Avalonia.cs b/MapControl/Avalonia/MapOverlay.Avalonia.cs index 7ea7671d..ae3d3e3e 100644 --- a/MapControl/Avalonia/MapOverlay.Avalonia.cs +++ b/MapControl/Avalonia/MapOverlay.Avalonia.cs @@ -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 FontFamilyProperty = DependencyPropertyHelper.AddOwner(TextElement.FontFamilyProperty); @@ -51,14 +50,82 @@ namespace MapControl public static readonly StyledProperty StrokeMiterLimitProperty = DependencyPropertyHelper.Register(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 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))); + } + } } } diff --git a/MapControl/Shared/MapOverlay.cs b/MapControl/Shared/MapOverlay.cs deleted file mode 100644 index 188bdf66..00000000 --- a/MapControl/Shared/MapOverlay.cs +++ /dev/null @@ -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; -#endif - -namespace MapControl -{ - /// - /// Base class for map overlays with background, foreground, stroke and font properties. - /// - 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); - } - } -} diff --git a/MapControl/UWP/MapControl.UWP.csproj b/MapControl/UWP/MapControl.UWP.csproj index 9b28d840..67a50816 100644 --- a/MapControl/UWP/MapControl.UWP.csproj +++ b/MapControl/UWP/MapControl.UWP.csproj @@ -119,9 +119,6 @@ MapItemsControl.cs - - MapOverlay.cs - MapPanel.cs diff --git a/MapControl/WPF/MapGraticule.WPF.cs b/MapControl/WPF/MapGraticule.WPF.cs index 0919ae49..e8b78a37 100644 --- a/MapControl/WPF/MapGraticule.WPF.cs +++ b/MapControl/WPF/MapGraticule.WPF.cs @@ -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(); diff --git a/MapControl/WPF/MapOverlay.WPF.cs b/MapControl/WPF/MapOverlay.WPF.cs index d492efc6..1c1f172f 100644 --- a/MapControl/WPF/MapOverlay.WPF.cs +++ b/MapControl/WPF/MapOverlay.WPF.cs @@ -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(TextElement.FontFamilyProperty); @@ -52,14 +51,82 @@ namespace MapControl public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyPropertyHelper.AddOwner(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))); + } + } } } diff --git a/MapControl/WinUI/MapOverlay.WinUI.cs b/MapControl/WinUI/MapOverlay.WinUI.cs index dc225263..79c99172 100644 --- a/MapControl/WinUI/MapOverlay.WinUI.cs +++ b/MapControl/WinUI/MapOverlay.WinUI.cs @@ -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(nameof(FontFamily)); @@ -57,6 +55,84 @@ namespace MapControl public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyPropertyHelper.Register(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) diff --git a/MapControl/WinUI/MapPolypoint.WinUI.cs b/MapControl/WinUI/MapPolypoint.WinUI.cs index a62f37c8..3020b128 100644 --- a/MapControl/WinUI/MapPolypoint.WinUI.cs +++ b/MapControl/WinUI/MapPolypoint.WinUI.cs @@ -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])