// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control // © 2018 Clemens Fischer // Licensed under the Microsoft Public License (Ms-PL) using System.Collections.Generic; using System.Linq; using Windows.UI.Xaml; using Windows.UI.Xaml.Media; namespace MapControl { /// /// A polyline defined by a collection of Locations. /// public class MapPolyline : MapShape { public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register( nameof(Locations), typeof(IEnumerable), typeof(MapPolyline), new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsPropertyChanged(e))); /// /// Gets or sets the Locations that define the polyline points. /// public IEnumerable Locations { get { return (IEnumerable)GetValue(LocationsProperty); } set { SetValue(LocationsProperty, value); } } protected override void UpdateData() { ((PathGeometry)Data).Figures.Clear(); if (ParentMap != null && Locations != null) { var locations = Locations; var offset = GetLongitudeOffset(); if (offset != 0d) { locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset)); } var points = locations.Select(loc => ParentMap.MapProjection.LocationToViewportPoint(loc)).ToList(); if (points.Count >= 2) { CreatePolylineFigures(points); } } } } }