XAML-Map-Control/MapControl/Shared/MapPolygon.cs

60 lines
1.7 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2022-01-14 20:22:56 +01:00
// © 2022 Clemens Fischer
// 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
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>
2021-11-17 23:17:11 +01:00
#if !UWP
2021-06-14 21:41:37 +02:00
[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()
{
2020-05-13 18:17:28 +02:00
var pathFigures = ((PathGeometry)Data).Figures;
pathFigures.Clear();
2020-05-13 18:17:28 +02:00
if (ParentMap != null && Locations != null)
{
2020-05-13 18:17:28 +02:00
var longitudeOffset = GetLongitudeOffset(Location ?? Locations.FirstOrDefault());
AddPolylineLocations(pathFigures, Locations, longitudeOffset, true);
}
}
}
}