// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © 2023 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
{
///
/// A polygon defined by a collection of Locations.
///
public class MapPolygon : MapPath
{
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable), typeof(MapPolygon),
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).DataCollectionPropertyChanged(e)));
///
/// Gets or sets the Locations that define the polygon points.
///
#if !UWP
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
#endif
public IEnumerable Locations
{
get => (IEnumerable)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);
}
}
}
}