2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2012-05-04 12:52:20 +02:00
|
|
|
|
// Copyright © 2012 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
#if WINRT
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
|
#else
|
2012-04-25 22:02:53 +02:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
#endif
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
public partial class MapPolyline : IMapElement
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-05-04 12:52:20 +02:00
|
|
|
|
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
2012-11-22 21:42:29 +01:00
|
|
|
|
"Locations", typeof(LocationCollection), typeof(MapPolyline),
|
|
|
|
|
|
new PropertyMetadata(null, LocationsPropertyChanged));
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
protected PathGeometry Geometry = new PathGeometry();
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
2012-05-04 12:52:20 +02:00
|
|
|
|
public LocationCollection Locations
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (LocationCollection)GetValue(LocationsProperty); }
|
|
|
|
|
|
set { SetValue(LocationsProperty, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
protected virtual bool IsClosed
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
get { return false; }
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
2012-05-04 12:52:20 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
protected virtual void UpdateGeometry(MapBase parentMap, LocationCollection locations)
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
if (parentMap != null && locations != null && locations.Count > 0)
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
var figure = new PathFigure
|
|
|
|
|
|
{
|
|
|
|
|
|
StartPoint = parentMap.MapTransform.Transform(locations[0]),
|
|
|
|
|
|
IsClosed = IsClosed,
|
|
|
|
|
|
IsFilled = IsClosed
|
|
|
|
|
|
};
|
2012-05-04 12:52:20 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
if (locations.Count > 1)
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
var segment = new PolyLineSegment();
|
2012-05-04 12:52:20 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
foreach (Location location in locations.Skip(1))
|
|
|
|
|
|
{
|
|
|
|
|
|
segment.Points.Add(parentMap.MapTransform.Transform(location));
|
|
|
|
|
|
}
|
2012-10-25 08:42:51 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
figure.Segments.Add(segment);
|
|
|
|
|
|
}
|
2012-10-25 08:42:51 +02:00
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
Geometry.Figures.Add(figure);
|
|
|
|
|
|
Geometry.Transform = parentMap.ViewportTransform;
|
2012-10-25 08:42:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
void IMapElement.ParentMapChanged(MapBase oldParentMap, MapBase newParentMap)
|
2012-10-25 08:42:51 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
UpdateGeometry(newParentMap, Locations);
|
2012-10-25 08:42:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-22 21:42:29 +01:00
|
|
|
|
private static void LocationsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
2012-10-25 08:42:51 +02:00
|
|
|
|
{
|
2012-11-22 21:42:29 +01:00
|
|
|
|
var polyline = (MapPolyline)obj;
|
|
|
|
|
|
polyline.UpdateGeometry(MapPanel.GetParentMap(polyline), (LocationCollection)e.NewValue);
|
2012-10-25 08:42:51 +02:00
|
|
|
|
}
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|