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-02-13 20:11:16 +01:00
|
|
|
|
protected 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
|
|
|
|
partial void SetDataTransform()
|
2018-02-09 17:43:47 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (parentMap != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var transform = new TransformGroup();
|
2018-02-13 20:11:16 +01:00
|
|
|
|
var offsetX = GetLongitudeOffset() * parentMap.MapProjection.TrueScale;
|
|
|
|
|
|
|
|
|
|
|
|
transform.Children.Add(new TranslateTransform(offsetX, 0d));
|
2018-02-09 17:43:47 +01:00
|
|
|
|
transform.Children.Add(parentMap.MapProjection.ViewportTransform);
|
|
|
|
|
|
|
|
|
|
|
|
Data.Transform = transform;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Data.Transform = Transform.Identity;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var transform = (TransformGroup)Data.Transform;
|
|
|
|
|
|
var offset = (TranslateTransform)transform.Children[0];
|
|
|
|
|
|
|
|
|
|
|
|
offset.X = GetLongitudeOffset() * parentMap.MapProjection.TrueScale;
|
|
|
|
|
|
|
|
|
|
|
|
if (e.ProjectionChanged)
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.Children[1] = parentMap.MapProjection.ViewportTransform;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (e.ProjectionChanged || parentMap.MapProjection.IsAzimuthal)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateData();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (Fill != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
InvalidateVisual(); // Fill brush may be rendered only partially or not at all
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-02-14 18:10:53 +01:00
|
|
|
|
protected void AddPolylineFigure(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)
|
|
|
|
|
|
{
|
|
|
|
|
|
var points = locations.Select(loc => LocationToPoint(loc));
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|