2018-02-09 17:43:47 +01:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
|
|
|
|
// © 2018 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-02-14 18:10:53 +01:00
|
|
|
|
using System.Collections.Generic;
|
2018-02-09 17:43:47 +01:00
|
|
|
|
using System.Collections.Specialized;
|
2018-02-14 18:10:53 +01:00
|
|
|
|
using System.Linq;
|
2018-02-09 17:43:47 +01:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public abstract partial class MapShape : Shape, IWeakEventListener
|
|
|
|
|
|
{
|
2018-04-30 23:13:50 +02:00
|
|
|
|
public Geometry Data { get; }
|
2018-02-09 17:43:47 +01:00
|
|
|
|
|
|
|
|
|
|
protected override Geometry DefiningGeometry
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Data; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-14 18:10:53 +01:00
|
|
|
|
bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateData();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-09 17:43:47 +01:00
|
|
|
|
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
2018-02-14 18:10:53 +01:00
|
|
|
|
INotifyCollectionChanged collection;
|
2018-02-09 17:43:47 +01:00
|
|
|
|
|
2018-02-14 18:10:53 +01:00
|
|
|
|
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
2018-02-14 18:10:53 +01:00
|
|
|
|
CollectionChangedEventManager.RemoveListener(collection, this);
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-14 18:10:53 +01:00
|
|
|
|
if ((collection = e.NewValue as INotifyCollectionChanged) != null)
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
2018-02-14 18:10:53 +01:00
|
|
|
|
CollectionChangedEventManager.AddListener(collection, this);
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UpdateData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-11 22:29:50 +02:00
|
|
|
|
protected void AddPolylineLocations(PathFigureCollection figures, IEnumerable<Location> locations, bool closed)
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
2018-02-14 18:10:53 +01:00
|
|
|
|
if (locations != null && locations.Count() >= 2)
|
|
|
|
|
|
{
|
2018-04-10 22:34:34 +02:00
|
|
|
|
var offset = GetLongitudeOffset();
|
|
|
|
|
|
if (offset != 0d)
|
|
|
|
|
|
{
|
|
|
|
|
|
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var points = locations.Select(loc => LocationToViewportPoint(loc));
|
2018-02-14 18:10:53 +01:00
|
|
|
|
var figure = new PathFigure
|
|
|
|
|
|
{
|
|
|
|
|
|
StartPoint = points.First(),
|
|
|
|
|
|
IsClosed = closed,
|
|
|
|
|
|
IsFilled = closed
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
figure.Segments.Add(new PolyLineSegment(points.Skip(1), true));
|
|
|
|
|
|
figures.Add(figure);
|
|
|
|
|
|
}
|
2018-02-09 17:43:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|