mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 06:26:41 +00:00
Updated MapPolypoint and PolygonCollection
This commit is contained in:
parent
81707c8ac0
commit
f86f1d3c28
6 changed files with 64 additions and 197 deletions
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Compile Remove="..\Shared\Matrix.cs" />
|
||||
<Compile Remove="..\Shared\PolygonCollection.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)'=='net462'">
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class of MapPolyline, MapPolygon and MapMultiPolygon.
|
||||
/// </summary>
|
||||
public class MapPolypoint : MapPath, IWeakEventListener
|
||||
public partial class MapPolypoint : MapPath
|
||||
{
|
||||
public static readonly DependencyProperty FillRuleProperty =
|
||||
DependencyPropertyHelper.Register<MapPolygon, FillRule>(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<Location> locations, bool closed)
|
||||
{
|
||||
using var context = ((StreamGeometry)Data).Open();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class PolygonCollection : ObservableCollection<IEnumerable<Location>>, 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<Location> polygon)
|
||||
{
|
||||
if (polygon is INotifyCollectionChanged addedPolygon)
|
||||
{
|
||||
CollectionChangedEventManager.AddListener(addedPolygon, this);
|
||||
}
|
||||
|
||||
base.InsertItem(index, polygon);
|
||||
}
|
||||
|
||||
protected override void SetItem(int index, IEnumerable<Location> 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<INotifyCollectionChanged>())
|
||||
{
|
||||
CollectionChangedEventManager.RemoveListener(polygon, this);
|
||||
}
|
||||
|
||||
base.ClearItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue