2018-02-09 17:43:47 +01:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2023-01-03 15:12:53 +01:00
|
|
|
|
// Copyright © 2023 Clemens Fischer
|
2018-02-09 17:43:47 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-13 18:17:28 +02:00
|
|
|
|
using System.Linq;
|
2021-06-14 21:41:37 +02:00
|
|
|
|
#if WINUI
|
|
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
|
using Microsoft.UI.Xaml.Media;
|
2021-11-17 23:17:11 +01:00
|
|
|
|
#elif UWP
|
2018-04-10 22:34:34 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
|
#else
|
2018-02-09 17:43:47 +01:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
2018-04-10 22:34:34 +02:00
|
|
|
|
#endif
|
2018-02-09 17:43:47 +01:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A polygon defined by a collection of Locations.
|
|
|
|
|
|
/// </summary>
|
2020-03-28 21:53:38 +01:00
|
|
|
|
public class MapPolygon : MapPath
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolygon),
|
|
|
|
|
|
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).DataCollectionPropertyChanged(e)));
|
|
|
|
|
|
|
2023-01-24 16:22:02 +01:00
|
|
|
|
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(FillRule), typeof(FillRule), typeof(MapPolygon),
|
|
|
|
|
|
new PropertyMetadata(FillRule.EvenOdd, (o, e) => ((PathGeometry)((MapPolygon)o).Data).FillRule = (FillRule)e.NewValue));
|
|
|
|
|
|
|
2018-02-09 17:43:47 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the Locations that define the polygon points.
|
|
|
|
|
|
/// </summary>
|
2021-11-17 23:17:11 +01:00
|
|
|
|
#if !UWP
|
2021-06-14 21:41:37 +02:00
|
|
|
|
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
|
2018-04-10 22:34:34 +02:00
|
|
|
|
#endif
|
2018-02-09 17:43:47 +01:00
|
|
|
|
public IEnumerable<Location> Locations
|
|
|
|
|
|
{
|
2022-08-06 10:40:59 +02:00
|
|
|
|
get => (IEnumerable<Location>)GetValue(LocationsProperty);
|
|
|
|
|
|
set => SetValue(LocationsProperty, 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 MapPolygon()
|
|
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
|
2020-05-13 18:17:28 +02:00
|
|
|
|
if (ParentMap != null && Locations != null)
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
2020-05-13 18:17:28 +02:00
|
|
|
|
var longitudeOffset = GetLongitudeOffset(Location ?? Locations.FirstOrDefault());
|
|
|
|
|
|
|
|
|
|
|
|
AddPolylineLocations(pathFigures, Locations, longitudeOffset, true);
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|