2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2016-02-23 20:07:30 +01:00
|
|
|
|
// © 2016 Clemens Fischer
|
2012-05-04 12:52:20 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2012-12-15 18:54:40 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.Specialized;
|
2015-08-09 20:04:44 +02:00
|
|
|
|
#if NETFX_CORE
|
2015-04-21 19:17:32 +02:00
|
|
|
|
using System.Collections;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml;
|
2015-03-20 18:49:17 +01:00
|
|
|
|
using Windows.UI.Xaml.Media;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
#else
|
2013-06-19 18:57:54 +02:00
|
|
|
|
using System.ComponentModel;
|
2015-03-20 18:49:17 +01: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
|
|
|
|
|
|
{
|
2013-10-13 16:32:51 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A polyline or polygon created from a collection of Locations.
|
|
|
|
|
|
/// </summary>
|
2013-05-25 08:53:50 +02:00
|
|
|
|
public partial class MapPolyline : MapPath
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2015-08-09 20:04:44 +02:00
|
|
|
|
#if NETFX_CORE
|
2016-08-08 20:36:02 +02:00
|
|
|
|
// Binding fails on Windows Runtime when property type is IEnumerable<Location>
|
2015-04-21 19:17:32 +02:00
|
|
|
|
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
|
|
|
|
|
"Locations", typeof(IEnumerable), typeof(MapPolyline),
|
2016-08-08 20:36:02 +02:00
|
|
|
|
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsChanged(e.OldValue as INotifyCollectionChanged, e.NewValue as INotifyCollectionChanged)));
|
2015-04-21 19:17:32 +02:00
|
|
|
|
#else
|
2013-02-12 19:30:58 +01:00
|
|
|
|
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
|
2014-12-17 21:38:28 +01:00
|
|
|
|
"Locations", typeof(IEnumerable<Location>), typeof(MapPolyline),
|
2016-08-08 20:36:02 +02:00
|
|
|
|
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsChanged(e.OldValue as INotifyCollectionChanged, e.NewValue as INotifyCollectionChanged)));
|
2015-04-21 19:17:32 +02:00
|
|
|
|
#endif
|
2012-11-26 19:17:12 +01:00
|
|
|
|
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
|
|
|
|
|
|
"IsClosed", typeof(bool), typeof(MapPolyline),
|
2013-05-25 08:53:50 +02:00
|
|
|
|
new PropertyMetadata(false, (o, e) => ((MapPolyline)o).UpdateData()));
|
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>
|
2015-08-09 20:04:44 +02:00
|
|
|
|
#if !NETFX_CORE
|
2013-06-19 18:57:54 +02:00
|
|
|
|
[TypeConverter(typeof(LocationCollectionConverter))]
|
|
|
|
|
|
#endif
|
2012-12-15 18:54:40 +01:00
|
|
|
|
public IEnumerable<Location> Locations
|
2012-05-04 12:52:20 +02:00
|
|
|
|
{
|
2012-12-15 18:54:40 +01:00
|
|
|
|
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
|
2012-05-04 12:52:20 +02:00
|
|
|
|
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
|
|
|
|
|
2015-03-20 18:49:17 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the FillRule of the PathGeometry that represents the polyline.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public FillRule FillRule
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return (FillRule)GetValue(FillRuleProperty); }
|
|
|
|
|
|
set { SetValue(FillRuleProperty, value); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-08 20:36:02 +02:00
|
|
|
|
private void LocationsChanged(INotifyCollectionChanged oldCollection, INotifyCollectionChanged newCollection)
|
2012-12-15 18:54:40 +01:00
|
|
|
|
{
|
2012-12-15 19:11:54 +01:00
|
|
|
|
if (oldCollection != null)
|
2012-12-15 18:54:40 +01:00
|
|
|
|
{
|
2016-08-08 20:36:02 +02:00
|
|
|
|
oldCollection.CollectionChanged -= LocationCollectionChanged;
|
2012-12-15 18:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-12-15 19:11:54 +01:00
|
|
|
|
if (newCollection != null)
|
2012-12-15 18:54:40 +01:00
|
|
|
|
{
|
2016-08-08 20:36:02 +02:00
|
|
|
|
newCollection.CollectionChanged += LocationCollectionChanged;
|
2012-12-15 18:54:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-08 20:36:02 +02:00
|
|
|
|
UpdateData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateData();
|
2012-12-15 18:54:40 +01:00
|
|
|
|
}
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|