2018-02-09 17:43:47 +01:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2021-01-13 21:19:27 +01:00
|
|
|
|
// © 2021 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
|
|
|
|
|
|
/// elements are both supposed to trigger a UI update.
|
|
|
|
|
|
/// </summary>
|
2020-03-28 21:53:38 +01:00
|
|
|
|
public class MapMultiPolygon : MapPath
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty PolygonsProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(Polygons), typeof(IEnumerable<IEnumerable<Location>>), typeof(MapMultiPolygon),
|
|
|
|
|
|
new PropertyMetadata(null, (o, e) => ((MapMultiPolygon)o).DataCollectionPropertyChanged(e)));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the Locations that define the multi-polygon points.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public IEnumerable<IEnumerable<Location>> Polygons
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (IEnumerable<IEnumerable<Location>>)GetValue(PolygonsProperty); }
|
|
|
|
|
|
set { SetValue(PolygonsProperty, 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()
|
|
|
|
|
|
{
|
2020-05-13 18:17:28 +02:00
|
|
|
|
var pathFigures = ((PathGeometry)Data).Figures;
|
|
|
|
|
|
pathFigures.Clear();
|
2018-02-09 17:43:47 +01:00
|
|
|
|
|
|
|
|
|
|
if (ParentMap != null && Polygons != null)
|
|
|
|
|
|
{
|
2020-05-13 18:17:28 +02:00
|
|
|
|
var longitudeOffset = GetLongitudeOffset(Location);
|
|
|
|
|
|
|
2018-02-14 18:10:53 +01:00
|
|
|
|
foreach (var polygon in Polygons)
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
2020-05-13 18:17:28 +02:00
|
|
|
|
AddPolylineLocations(pathFigures, polygon, longitudeOffset, true);
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|