2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2015-01-20 17:52:02 +01:00
|
|
|
|
// © 2015 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2013-02-12 19:30:58 +01:00
|
|
|
|
using System.Linq;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2013-04-12 19:59:16 +02:00
|
|
|
|
public partial class MapPolyline
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-04-12 19:59:16 +02:00
|
|
|
|
public MapPolyline()
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-05-25 08:53:50 +02:00
|
|
|
|
Data = new StreamGeometry();
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
2013-02-12 19:30:58 +01:00
|
|
|
|
|
2013-05-25 08:53:50 +02:00
|
|
|
|
protected override void UpdateData()
|
2013-02-12 19:30:58 +01:00
|
|
|
|
{
|
2013-05-25 08:53:50 +02:00
|
|
|
|
var geometry = (StreamGeometry)Data;
|
2013-02-12 19:30:58 +01:00
|
|
|
|
var locations = Locations;
|
|
|
|
|
|
Location first;
|
|
|
|
|
|
|
2013-04-12 19:59:16 +02:00
|
|
|
|
if (ParentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
|
2013-02-12 19:30:58 +01:00
|
|
|
|
{
|
2013-04-12 19:59:16 +02:00
|
|
|
|
using (var context = geometry.Open())
|
2013-02-12 19:30:58 +01:00
|
|
|
|
{
|
2013-04-12 19:59:16 +02:00
|
|
|
|
var startPoint = ParentMap.MapTransform.Transform(first);
|
|
|
|
|
|
var points = locations.Skip(1).Select(l => ParentMap.MapTransform.Transform(l)).ToList();
|
2013-02-12 19:30:58 +01:00
|
|
|
|
|
|
|
|
|
|
context.BeginFigure(startPoint, IsClosed, IsClosed);
|
|
|
|
|
|
context.PolyLineTo(points, true, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-04-12 19:59:16 +02:00
|
|
|
|
geometry.Transform = ParentMap.ViewportTransform;
|
2013-02-12 19:30:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2013-04-12 19:59:16 +02:00
|
|
|
|
geometry.Clear();
|
|
|
|
|
|
geometry.ClearValue(Geometry.TransformProperty);
|
2013-02-12 19:30:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|