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),
|
2012-11-26 19:17:12 +01:00
|
|
|
|
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).UpdateGeometry()));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
|
|
|
|
|
|
"IsClosed", typeof(bool), typeof(MapPolyline),
|
|
|
|
|
|
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateGeometry()));
|
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-11-26 19:17:12 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the locations that define the polyline points.
|
|
|
|
|
|
/// </summary>
|
2012-05-04 12:52:20 +02:00
|
|
|
|
public LocationCollection Locations
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (LocationCollection)GetValue(LocationsProperty); }
|
|
|
|
|
|
set { SetValue(LocationsProperty, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-26 19:17:12 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets a value that indicates if the polyline is closed, i.e. is a polygon.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsClosed
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-11-26 19:17:12 +01:00
|
|
|
|
get { return (bool)GetValue(IsClosedProperty); }
|
|
|
|
|
|
set { SetValue(IsClosedProperty, value); }
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
2012-05-04 12:52:20 +02:00
|
|
|
|
|
2012-11-26 19:17:12 +01:00
|
|
|
|
protected virtual void UpdateGeometry()
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-11-26 19:17:12 +01:00
|
|
|
|
var parentMap = MapPanel.GetParentMap(this);
|
|
|
|
|
|
var locations = Locations;
|
|
|
|
|
|
|
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-26 19:17:12 +01:00
|
|
|
|
UpdateGeometry();
|
2012-10-25 08:42:51 +02:00
|
|
|
|
}
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|