mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
MapMultiPolygon
This commit is contained in:
parent
5b9ad68c57
commit
dbd32361b5
11 changed files with 217 additions and 61 deletions
44
MapControl/Shared/MapMultiPolygon.cs
Normal file
44
MapControl/Shared/MapMultiPolygon.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
#if WPF
|
||||
using System.Windows;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// A multi-polygon defined by a collection of collections of Locations.
|
||||
/// Allows to draw filled polygons with holes.
|
||||
///
|
||||
/// A PolygonCollection (with ObservableCollection of Location elements) may be used
|
||||
/// for the Polygons property if collection changes of the property itself and its
|
||||
/// elements are both supposed to trigger UI updates.
|
||||
/// </summary>
|
||||
public class MapMultiPolygon : MapPolypoint
|
||||
{
|
||||
public static readonly DependencyProperty PolygonsProperty =
|
||||
DependencyPropertyHelper.Register<MapMultiPolygon, IEnumerable<IEnumerable<Location>>>(nameof(Polygons), null,
|
||||
(polygon, oldValue, newValue) => polygon.DataCollectionPropertyChanged(oldValue, newValue));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Locations that define the multi-polygon points.
|
||||
/// </summary>
|
||||
public IEnumerable<IEnumerable<Location>> Polygons
|
||||
{
|
||||
get => (IEnumerable<IEnumerable<Location>>)GetValue(PolygonsProperty);
|
||||
set => SetValue(PolygonsProperty, value);
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
UpdateData(Polygons);
|
||||
}
|
||||
}
|
||||
}
|
||||
70
MapControl/Shared/PolygonCollection.cs
Normal file
70
MapControl/Shared/PolygonCollection.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 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;
|
||||
|
||||
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>>
|
||||
{
|
||||
private void PolygonChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, sender, sender));
|
||||
}
|
||||
|
||||
protected override void InsertItem(int index, IEnumerable<Location> polygon)
|
||||
{
|
||||
if (polygon is INotifyCollectionChanged addedPolygon)
|
||||
{
|
||||
addedPolygon.CollectionChanged += PolygonChanged;
|
||||
}
|
||||
|
||||
base.InsertItem(index, polygon);
|
||||
}
|
||||
|
||||
protected override void SetItem(int index, IEnumerable<Location> polygon)
|
||||
{
|
||||
if (this[index] is INotifyCollectionChanged removedPolygon)
|
||||
{
|
||||
removedPolygon.CollectionChanged -= PolygonChanged;
|
||||
}
|
||||
|
||||
if (polygon is INotifyCollectionChanged addedPolygon)
|
||||
{
|
||||
addedPolygon.CollectionChanged += PolygonChanged;
|
||||
}
|
||||
|
||||
base.SetItem(index, polygon);
|
||||
}
|
||||
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
if (this[index] is INotifyCollectionChanged removedPolygon)
|
||||
{
|
||||
removedPolygon.CollectionChanged -= PolygonChanged;
|
||||
}
|
||||
|
||||
base.RemoveItem(index);
|
||||
}
|
||||
|
||||
protected override void ClearItems()
|
||||
{
|
||||
foreach (var polygon in this.OfType<INotifyCollectionChanged>())
|
||||
{
|
||||
polygon.CollectionChanged -= PolygonChanged;
|
||||
}
|
||||
|
||||
base.ClearItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue