// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2020 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using System.Linq;
#if WINDOWS_UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
{
///
/// A polyline defined by a collection of Locations.
///
public class MapPolyline : MapPath
{
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).DataCollectionPropertyChanged(e)));
///
/// Gets or sets the Locations that define the polyline points.
///
#if !WINDOWS_UWP
[TypeConverter(typeof(LocationCollectionConverter))]
#endif
public IEnumerable Locations
{
get { return (IEnumerable)GetValue(LocationsProperty); }
set { SetValue(LocationsProperty, value); }
}
public MapPolyline()
{
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, false);
}
}
}
}