XAML-Map-Control/MapControl/MapPolyline.Silverlight.WinRT.cs

61 lines
1.6 KiB
C#
Raw Normal View History

// XAML Map Control - http://xamlmapcontrol.codeplex.com/
// Copyright © Clemens Fischer 2012-2013
// Licensed under the Microsoft Public License (Ms-PL)
using System.Linq;
#if NETFX_CORE
using Windows.UI.Xaml.Media;
#else
using System.Windows.Media;
#endif
namespace MapControl
{
public partial class MapPolyline
{
public MapPolyline()
: base(new PathGeometry())
{
}
protected override void UpdateGeometry()
{
var geometry = (PathGeometry)Geometry;
var locations = Locations;
Location first;
if (ParentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
{
var figure = new PathFigure
{
StartPoint = ParentMap.MapTransform.Transform(first),
IsClosed = IsClosed,
IsFilled = IsClosed
};
var segment = new PolyLineSegment();
foreach (var location in locations.Skip(1))
{
segment.Points.Add(ParentMap.MapTransform.Transform(location));
}
if (segment.Points.Count > 0)
{
figure.Segments.Add(segment);
}
geometry.Figures.Clear();
geometry.Figures.Add(figure);
geometry.Transform = ParentMap.ViewportTransform;
}
else
{
geometry.Figures.Clear();
geometry.ClearValue(Geometry.TransformProperty);
}
}
}
}