2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2018-02-09 17:43:47 +01:00
|
|
|
|
// © 2018 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;
|
|
|
|
|
|
using System.ComponentModel;
|
2013-02-12 19:30:58 +01:00
|
|
|
|
using System.Linq;
|
2015-03-20 18:49:17 +01:00
|
|
|
|
using System.Windows;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2018-02-09 17:43:47 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A polyline defined by a collection of Locations.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class MapPolyline : MapShape
|
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
|
|
|
|
|
2018-02-13 20:11:16 +01:00
|
|
|
|
public MapPolyline()
|
|
|
|
|
|
: base(new PathGeometry())
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
[TypeConverter(typeof(LocationCollectionConverter))]
|
|
|
|
|
|
public IEnumerable<Location> Locations
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
|
|
|
|
|
|
set { SetValue(LocationsProperty, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-25 08:53:50 +02:00
|
|
|
|
protected override void UpdateData()
|
2013-02-12 19:30:58 +01:00
|
|
|
|
{
|
2018-02-13 20:11:16 +01:00
|
|
|
|
var figures = ((PathGeometry)Data).Figures;
|
|
|
|
|
|
figures.Clear();
|
2013-02-12 19:30:58 +01:00
|
|
|
|
|
2018-02-12 23:28:32 +01:00
|
|
|
|
if (ParentMap != null && Locations != null && Locations.Count() >= 2)
|
2013-02-12 19:30:58 +01:00
|
|
|
|
{
|
2018-02-09 17:43:47 +01:00
|
|
|
|
var points = Locations.Select(loc => LocationToPoint(loc));
|
|
|
|
|
|
var polyline = new PolyLineSegment(points.Skip(1), true);
|
2013-02-12 19:30:58 +01:00
|
|
|
|
|
2018-02-13 20:11:16 +01:00
|
|
|
|
figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, false));
|
2013-02-12 19:30:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|