XAML-Map-Control/MapControl/Shared/MapPolygon.cs
2022-01-14 20:22:56 +01:00

60 lines
1.7 KiB
C#

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using System.Linq;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
{
/// <summary>
/// A polygon defined by a collection of Locations.
/// </summary>
public class MapPolygon : MapPath
{
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolygon),
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).DataCollectionPropertyChanged(e)));
/// <summary>
/// Gets or sets the Locations that define the polygon points.
/// </summary>
#if !UWP
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
#endif
public IEnumerable<Location> Locations
{
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
set { SetValue(LocationsProperty, value); }
}
public MapPolygon()
{
Data = new PathGeometry();
}
protected override void UpdateData()
{
var pathFigures = ((PathGeometry)Data).Figures;
pathFigures.Clear();
if (ParentMap != null && Locations != null)
{
var longitudeOffset = GetLongitudeOffset(Location ?? Locations.FirstOrDefault());
AddPolylineLocations(pathFigures, Locations, longitudeOffset, true);
}
}
}
}