From f86f1d3c2886dc743924d141a32a54cb83ef20a3 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Wed, 21 Jan 2026 22:27:29 +0100 Subject: [PATCH] Updated MapPolypoint and PolygonCollection --- MapControl/Avalonia/MapPolypoint.Avalonia.cs | 42 +----------- MapControl/Shared/MapPolypoint.cs | 62 ++++++++++++++++++ MapControl/WPF/MapControl.WPF.csproj | 1 - MapControl/WPF/MapPolypoint.WPF.cs | 45 +------------ MapControl/WPF/PolygonCollection.WPF.cs | 69 -------------------- MapControl/WinUI/MapPolypoint.WinUI.cs | 42 ------------ 6 files changed, 64 insertions(+), 197 deletions(-) create mode 100644 MapControl/Shared/MapPolypoint.cs delete mode 100644 MapControl/WPF/PolygonCollection.WPF.cs diff --git a/MapControl/Avalonia/MapPolypoint.Avalonia.cs b/MapControl/Avalonia/MapPolypoint.Avalonia.cs index 29ac6b94..f3111d30 100644 --- a/MapControl/Avalonia/MapPolypoint.Avalonia.cs +++ b/MapControl/Avalonia/MapPolypoint.Avalonia.cs @@ -1,53 +1,13 @@ using Avalonia; using Avalonia.Media; using System; -using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; namespace MapControl { - /// - /// Base class of MapPolyline and MapPolygon. - /// - public class MapPolypoint : MapPath + public partial class MapPolypoint : MapPath { - public static readonly StyledProperty FillRuleProperty = - DependencyPropertyHelper.Register(nameof(FillRule), FillRule.EvenOdd, - (polypoint, oldValue, newValue) => ((PathGeometry)polypoint.Data).FillRule = newValue); - - public FillRule FillRule - { - get => GetValue(FillRuleProperty); - set => SetValue(FillRuleProperty, value); - } - - protected MapPolypoint() - { - Data = new PathGeometry(); - } - - protected void DataCollectionPropertyChanged(IEnumerable oldValue, IEnumerable newValue) - { - if (oldValue is INotifyCollectionChanged oldCollection) - { - oldCollection.CollectionChanged -= DataCollectionChanged; - } - - if (newValue is INotifyCollectionChanged newCollection) - { - newCollection.CollectionChanged += DataCollectionChanged; - } - - UpdateData(); - } - - protected void DataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - UpdateData(); - } - protected void UpdateData(IEnumerable locations, bool closed) { var figures = new PathFigures(); diff --git a/MapControl/Shared/MapPolypoint.cs b/MapControl/Shared/MapPolypoint.cs new file mode 100644 index 00000000..2195d738 --- /dev/null +++ b/MapControl/Shared/MapPolypoint.cs @@ -0,0 +1,62 @@ +using System.Collections; +using System.Collections.Specialized; +#if WPF +using System.Windows; +using System.Windows.Media; +using PolypointGeometry = System.Windows.Media.StreamGeometry; +#elif UWP +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; +using PolypointGeometry = Windows.UI.Xaml.Media.PathGeometry; +#elif WINUI +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; +using PolypointGeometry = Microsoft.UI.Xaml.Media.PathGeometry; +#elif AVALONIA +using Avalonia.Media; +using PolypointGeometry = Avalonia.Media.PathGeometry; +#endif + +namespace MapControl +{ + /// + /// Base class of MapPolyline and MapPolygon and MapMultiPolygon. + /// + public partial class MapPolypoint + { + public static readonly DependencyProperty FillRuleProperty = + DependencyPropertyHelper.Register(nameof(FillRule), FillRule.EvenOdd, + (polypoint, oldValue, newValue) => ((PolypointGeometry)polypoint.Data).FillRule = newValue); + + public FillRule FillRule + { + get => (FillRule)GetValue(FillRuleProperty); + set => SetValue(FillRuleProperty, value); + } + + protected MapPolypoint() + { + Data = new PolypointGeometry(); + } + + protected void DataCollectionPropertyChanged(IEnumerable oldValue, IEnumerable newValue) + { + if (oldValue is INotifyCollectionChanged oldCollection) + { + oldCollection.CollectionChanged -= DataCollectionChanged; + } + + if (newValue is INotifyCollectionChanged newCollection) + { + newCollection.CollectionChanged += DataCollectionChanged; + } + + UpdateData(); + } + + protected void DataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + UpdateData(); + } + } +} diff --git a/MapControl/WPF/MapControl.WPF.csproj b/MapControl/WPF/MapControl.WPF.csproj index ed55aac4..f4398846 100644 --- a/MapControl/WPF/MapControl.WPF.csproj +++ b/MapControl/WPF/MapControl.WPF.csproj @@ -18,7 +18,6 @@ - diff --git a/MapControl/WPF/MapPolypoint.WPF.cs b/MapControl/WPF/MapPolypoint.WPF.cs index 1dd90555..c5aa21a7 100644 --- a/MapControl/WPF/MapPolypoint.WPF.cs +++ b/MapControl/WPF/MapPolypoint.WPF.cs @@ -1,55 +1,12 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; -using System.Windows; using System.Windows.Media; namespace MapControl { - /// - /// Base class of MapPolyline, MapPolygon and MapMultiPolygon. - /// - public class MapPolypoint : MapPath, IWeakEventListener + public partial class MapPolypoint : MapPath { - public static readonly DependencyProperty FillRuleProperty = - DependencyPropertyHelper.Register(nameof(FillRule), FillRule.EvenOdd, - (polypoint, oldValue, newValue) => ((StreamGeometry)polypoint.Data).FillRule = newValue); - - public FillRule FillRule - { - get => (FillRule)GetValue(FillRuleProperty); - set => SetValue(FillRuleProperty, value); - } - - protected MapPolypoint() - { - Data = new StreamGeometry(); - } - - protected void DataCollectionPropertyChanged(IEnumerable oldValue, IEnumerable newValue) - { - if (oldValue is INotifyCollectionChanged oldCollection) - { - CollectionChangedEventManager.RemoveListener(oldCollection, this); - } - - if (newValue is INotifyCollectionChanged newCollection) - { - CollectionChangedEventManager.AddListener(newCollection, this); - } - - UpdateData(); - } - - bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e) - { - UpdateData(); - - return true; - } - protected void UpdateData(IEnumerable locations, bool closed) { using var context = ((StreamGeometry)Data).Open(); diff --git a/MapControl/WPF/PolygonCollection.WPF.cs b/MapControl/WPF/PolygonCollection.WPF.cs deleted file mode 100644 index fc800aae..00000000 --- a/MapControl/WPF/PolygonCollection.WPF.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.Linq; -using System.Windows; - -namespace MapControl -{ - /// - /// An ObservableCollection of IEnumerable of Location. PolygonCollection adds a CollectionChanged - /// listener to each element that implements INotifyCollectionChanged and, when such an element changes, - /// fires its own CollectionChanged event with NotifyCollectionChangedAction.Replace for that element. - /// - public class PolygonCollection : ObservableCollection>, IWeakEventListener - { - public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) - { - OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, sender, sender)); - - return true; - } - - protected override void InsertItem(int index, IEnumerable polygon) - { - if (polygon is INotifyCollectionChanged addedPolygon) - { - CollectionChangedEventManager.AddListener(addedPolygon, this); - } - - base.InsertItem(index, polygon); - } - - protected override void SetItem(int index, IEnumerable polygon) - { - if (this[index] is INotifyCollectionChanged removedPolygon) - { - CollectionChangedEventManager.RemoveListener(removedPolygon, this); - } - - if (polygon is INotifyCollectionChanged addedPolygon) - { - CollectionChangedEventManager.AddListener(addedPolygon, this); - } - - base.SetItem(index, polygon); - } - - protected override void RemoveItem(int index) - { - if (this[index] is INotifyCollectionChanged removedPolygon) - { - CollectionChangedEventManager.RemoveListener(removedPolygon, this); - } - - base.RemoveItem(index); - } - - protected override void ClearItems() - { - foreach (var polygon in this.OfType()) - { - CollectionChangedEventManager.RemoveListener(polygon, this); - } - - base.ClearItems(); - } - } -} diff --git a/MapControl/WinUI/MapPolypoint.WinUI.cs b/MapControl/WinUI/MapPolypoint.WinUI.cs index 31b5f89a..4dce9bbc 100644 --- a/MapControl/WinUI/MapPolypoint.WinUI.cs +++ b/MapControl/WinUI/MapPolypoint.WinUI.cs @@ -1,58 +1,16 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; #if UWP -using Windows.UI.Xaml; using Windows.UI.Xaml.Media; #else -using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media; #endif namespace MapControl { - /// - /// Base class of MapPolyline and MapPolygon. - /// public partial class MapPolypoint : MapPath { - public static readonly DependencyProperty FillRuleProperty = - DependencyPropertyHelper.Register(nameof(FillRule), FillRule.EvenOdd, - (polypoint, oldValue, newValue) => ((PathGeometry)polypoint.Data).FillRule = newValue); - - public FillRule FillRule - { - get => (FillRule)GetValue(FillRuleProperty); - set => SetValue(FillRuleProperty, value); - } - - protected MapPolypoint() - { - Data = new PathGeometry(); - } - - protected void DataCollectionPropertyChanged(IEnumerable oldValue, IEnumerable newValue) - { - if (oldValue is INotifyCollectionChanged oldCollection) - { - oldCollection.CollectionChanged -= DataCollectionChanged; - } - - if (newValue is INotifyCollectionChanged newCollection) - { - newCollection.CollectionChanged += DataCollectionChanged; - } - - UpdateData(); - } - - protected void DataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - UpdateData(); - } - protected void UpdateData(IEnumerable locations, bool closed) { var figures = ((PathGeometry)Data).Figures;