XAML-Map-Control/MapControl/WPF/MapPath.WPF.cs
2020-03-28 21:53:38 +01:00

71 lines
2.1 KiB
C#

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2020 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace MapControl
{
public partial class MapPath : Shape, IWeakEventListener
{
public static readonly DependencyProperty DataProperty = Path.DataProperty.AddOwner(typeof(MapPath));
public Geometry Data
{
get { return (Geometry)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
protected override Geometry DefiningGeometry
{
get { return Data; }
}
public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
{
UpdateData();
return true;
}
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
{
INotifyCollectionChanged collection;
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
{
CollectionChangedEventManager.RemoveListener(collection, this);
}
if ((collection = e.NewValue as INotifyCollectionChanged) != null)
{
CollectionChangedEventManager.AddListener(collection, this);
}
UpdateData();
}
protected void AddPolylineLocations(PathFigureCollection figures, IEnumerable<Location> locations, bool closed)
{
if (locations != null && locations.Count() >= 2)
{
var points = locations.Select(loc => LocationToView(loc));
var figure = new PathFigure
{
StartPoint = points.First(),
IsClosed = closed,
IsFilled = closed
};
figure.Segments.Add(new PolyLineSegment(points.Skip(1), true));
figures.Add(figure);
}
}
}
}