XAML-Map-Control/MapControl/WPF/MapPolyline.WPF.cs

52 lines
1.7 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
2017-08-04 21:38:58 +02:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Media;
namespace MapControl
{
/// <summary>
/// A polyline defined by a collection of Locations.
/// </summary>
public class MapPolyline : MapShape
{
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).DataCollectionPropertyChanged(e)));
public MapPolyline()
: base(new PathGeometry())
{
}
2017-08-04 21:38:58 +02:00
/// <summary>
/// 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); }
}
protected override void UpdateData()
{
var figures = ((PathGeometry)Data).Figures;
figures.Clear();
if (ParentMap != null && Locations != null && Locations.Count() >= 2)
{
var points = Locations.Select(loc => LocationToPoint(loc));
var polyline = new PolyLineSegment(points.Skip(1), true);
figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, false));
}
}
}
}