2018-02-09 17:43:47 +01:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2024-02-03 21:01:53 +01:00
|
|
|
|
// Copyright © 2024 Clemens Fischer
|
2018-02-09 17:43:47 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A multi-polygon defined by a collection of collections of Locations.
|
2018-06-13 17:33:47 +02:00
|
|
|
|
/// Allows to draw polygons with holes.
|
2018-02-09 17:43:47 +01:00
|
|
|
|
///
|
|
|
|
|
|
/// A PolygonCollection (with ObservableCollection of Location elements) may be used
|
|
|
|
|
|
/// for the Polygons property if collection changes of the property itself and its
|
2023-01-24 16:22:02 +01:00
|
|
|
|
/// elements are both supposed to trigger UI updates.
|
2018-02-09 17:43:47 +01:00
|
|
|
|
/// </summary>
|
2020-03-28 21:53:38 +01:00
|
|
|
|
public class MapMultiPolygon : MapPath
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
2024-05-23 18:08:14 +02:00
|
|
|
|
public static readonly DependencyProperty PolygonsProperty =
|
|
|
|
|
|
DependencyPropertyHelper.Register<MapMultiPolygon, IEnumerable<IEnumerable<Location>>>(nameof(Polygons), null, false,
|
|
|
|
|
|
(polygon, oldValue, newValue) => polygon.DataCollectionPropertyChanged(oldValue, newValue));
|
2018-02-09 17:43:47 +01:00
|
|
|
|
|
2024-05-23 18:08:14 +02:00
|
|
|
|
public static readonly DependencyProperty FillRuleProperty =
|
|
|
|
|
|
DependencyPropertyHelper.Register<MapMultiPolygon, FillRule>(nameof(FillRule), FillRule.EvenOdd, false,
|
|
|
|
|
|
(polygon, oldValue, newValue) => ((PathGeometry)polygon.Data).FillRule = newValue);
|
2023-01-24 16:22:02 +01:00
|
|
|
|
|
2018-02-09 17:43:47 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the Locations that define the multi-polygon points.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public IEnumerable<IEnumerable<Location>> Polygons
|
|
|
|
|
|
{
|
2022-08-06 10:40:59 +02:00
|
|
|
|
get => (IEnumerable<IEnumerable<Location>>)GetValue(PolygonsProperty);
|
|
|
|
|
|
set => SetValue(PolygonsProperty, value);
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-24 16:22:02 +01:00
|
|
|
|
public FillRule FillRule
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (FillRule)GetValue(FillRuleProperty);
|
|
|
|
|
|
set => SetValue(FillRuleProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-28 21:53:38 +01:00
|
|
|
|
public MapMultiPolygon()
|
|
|
|
|
|
{
|
|
|
|
|
|
Data = new PathGeometry();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-09 17:43:47 +01:00
|
|
|
|
protected override void UpdateData()
|
|
|
|
|
|
{
|
2023-12-13 14:55:49 +01:00
|
|
|
|
var figures = ((PathGeometry)Data).Figures;
|
|
|
|
|
|
figures.Clear();
|
|
|
|
|
|
AddMultiPolygonPoints(figures, Polygons);
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|