Version 4.4.0: Fixed MapPolyline performance on UWP. Added MapPolygon and MapMultiPolygon for WPF.

This commit is contained in:
ClemensF 2018-02-09 17:43:47 +01:00
parent cce5d6e0b4
commit d1552506f6
80 changed files with 673 additions and 550 deletions

View file

@ -0,0 +1,74 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
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
{
protected override void InsertItem(int index, IEnumerable<Location> polygon)
{
var observablePolygon = polygon as INotifyCollectionChanged;
if (observablePolygon != null)
{
CollectionChangedEventManager.AddListener(observablePolygon, this);
}
base.InsertItem(index, polygon);
}
protected override void SetItem(int index, IEnumerable<Location> polygon)
{
var observablePolygon = this[index] as INotifyCollectionChanged;
if (observablePolygon != null)
{
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
}
base.SetItem(index, polygon);
}
protected override void RemoveItem(int index)
{
var observablePolygon = this[index] as INotifyCollectionChanged;
if (observablePolygon != null)
{
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
}
base.RemoveItem(index);
}
protected override void ClearItems()
{
foreach (var observablePolygon in this.OfType<INotifyCollectionChanged>())
{
CollectionChangedEventManager.RemoveListener(observablePolygon, this);
}
base.ClearItems();
}
bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
{
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, sender, sender));
return true;
}
}
}