2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2022-01-14 20:22:56 +01:00
|
|
|
|
// © 2022 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2017-08-04 21:38:58 +02:00
|
|
|
|
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
|
2018-04-10 22:34:34 +02:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
|
#else
|
2015-03-20 18:49:17 +01:00
|
|
|
|
using System.Windows;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using System.Windows.Media;
|
2018-04-10 22:34:34 +02:00
|
|
|
|
#endif
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2018-02-09 17:43:47 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A polyline defined by a collection of Locations.
|
|
|
|
|
|
/// </summary>
|
2020-03-28 21:53:38 +01:00
|
|
|
|
public class MapPolyline : MapPath
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2018-02-09 17:43:47 +01:00
|
|
|
|
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
|
|
|
|
|
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
|
|
|
|
|
|
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).DataCollectionPropertyChanged(e)));
|
2013-02-12 19:30:58 +01:00
|
|
|
|
|
2017-08-04 21:38:58 +02:00
|
|
|
|
/// <summary>
|
2018-02-09 17:43:47 +01:00
|
|
|
|
/// Gets or sets the Locations that define the polyline points.
|
2017-08-04 21:38:58 +02:00
|
|
|
|
/// </summary>
|
2021-11-17 23:17:11 +01:00
|
|
|
|
#if !UWP
|
2021-06-14 21:41:37 +02:00
|
|
|
|
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
|
2018-04-10 22:34:34 +02:00
|
|
|
|
#endif
|
2017-08-04 21:38:58 +02:00
|
|
|
|
public IEnumerable<Location> Locations
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
|
|
|
|
|
|
set { SetValue(LocationsProperty, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-28 21:53:38 +01:00
|
|
|
|
public MapPolyline()
|
|
|
|
|
|
{
|
|
|
|
|
|
Data = new PathGeometry();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-25 08:53:50 +02:00
|
|
|
|
protected override void UpdateData()
|
2013-02-12 19:30:58 +01:00
|
|
|
|
{
|
2020-05-13 18:17:28 +02:00
|
|
|
|
var pathFigures = ((PathGeometry)Data).Figures;
|
|
|
|
|
|
pathFigures.Clear();
|
2013-02-12 19:30:58 +01:00
|
|
|
|
|
2020-05-13 18:17:28 +02:00
|
|
|
|
if (ParentMap != null && Locations != null)
|
2013-02-12 19:30:58 +01:00
|
|
|
|
{
|
2020-05-13 18:17:28 +02:00
|
|
|
|
var longitudeOffset = GetLongitudeOffset(Location ?? Locations.FirstOrDefault());
|
|
|
|
|
|
|
|
|
|
|
|
AddPolylineLocations(pathFigures, Locations, longitudeOffset, false);
|
2013-02-12 19:30:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|