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

56 lines
1.8 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 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
{
public partial class MapPolyline
{
2017-08-04 21:38:58 +02:00
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register(
nameof(FillRule), typeof(FillRule), typeof(MapPolyline), new FrameworkPropertyMetadata(
FillRule.EvenOdd, FrameworkPropertyMetadataOptions.AffectsRender,
(o, e) => ((StreamGeometry)((MapPolyline)o).Data).FillRule = (FillRule)e.NewValue));
public MapPolyline()
{
Data = new StreamGeometry();
}
2017-08-04 21:38:58 +02:00
/// <summary>
/// Gets or sets the locations that define the polyline points.
/// </summary>
[TypeConverter(typeof(LocationCollectionConverter))]
public IEnumerable<Location> Locations
{
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
set { SetValue(LocationsProperty, value); }
}
protected override void UpdateData()
{
var geometry = (StreamGeometry)Data;
if (ParentMap != null && Locations != null && Locations.Any())
{
using (var context = geometry.Open())
{
var points = Locations.Select(l => ParentMap.MapProjection.LocationToPoint(l));
context.BeginFigure(points.First(), IsClosed, IsClosed);
context.PolyLineTo(points.Skip(1).ToList(), true, false);
}
}
else
{
geometry.Clear();
}
}
}
}