2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2020-01-09 19:40:10 +01:00
|
|
|
|
// © 2020 Clemens Fischer
|
2012-11-23 16:16:09 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MapPanel
|
|
|
|
|
|
{
|
2019-07-08 23:00:57 +02:00
|
|
|
|
public static readonly DependencyProperty LocationProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"Location", typeof(Location), typeof(MapPanel),
|
|
|
|
|
|
new PropertyMetadata(null, (o, e) => (((FrameworkElement)o).Parent as MapPanel)?.InvalidateArrange()));
|
|
|
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty BoundingBoxProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"BoundingBox", typeof(BoundingBox), typeof(MapPanel),
|
|
|
|
|
|
new PropertyMetadata(null, (o, e) => (((FrameworkElement)o).Parent as MapPanel)?.InvalidateArrange()));
|
|
|
|
|
|
|
2012-11-23 16:16:09 +01:00
|
|
|
|
public static readonly DependencyProperty ParentMapProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"ParentMap", typeof(MapBase), typeof(MapPanel), new PropertyMetadata(null, ParentMapPropertyChanged));
|
|
|
|
|
|
|
2020-03-28 21:53:38 +01:00
|
|
|
|
private static readonly DependencyProperty ViewPositionProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"ViewPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata(null));
|
2018-04-30 23:13:50 +02:00
|
|
|
|
|
2017-09-05 20:57:17 +02:00
|
|
|
|
public static void InitMapElement(FrameworkElement element)
|
2012-11-23 16:16:09 +01:00
|
|
|
|
{
|
2017-09-05 20:57:17 +02:00
|
|
|
|
if (element is MapBase)
|
2014-11-19 21:11:14 +01:00
|
|
|
|
{
|
2017-09-05 20:57:17 +02:00
|
|
|
|
element.SetValue(ParentMapProperty, element);
|
2014-11-19 21:11:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2012-11-23 16:16:09 +01:00
|
|
|
|
{
|
2017-09-05 20:57:17 +02:00
|
|
|
|
// Workaround for missing property value inheritance in Windows Runtime.
|
|
|
|
|
|
// Loaded and Unloaded handlers set and clear the ParentMap property value.
|
2012-11-23 16:16:09 +01:00
|
|
|
|
|
2017-09-05 20:57:17 +02:00
|
|
|
|
element.Loaded += (s, e) => GetParentMap(element);
|
|
|
|
|
|
element.Unloaded += (s, e) => element.ClearValue(ParentMapProperty);
|
|
|
|
|
|
}
|
2012-11-23 16:16:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-30 23:13:50 +02:00
|
|
|
|
public static MapBase GetParentMap(FrameworkElement element)
|
2012-11-23 16:16:09 +01:00
|
|
|
|
{
|
|
|
|
|
|
var parentMap = (MapBase)element.GetValue(ParentMapProperty);
|
|
|
|
|
|
|
|
|
|
|
|
if (parentMap == null && (parentMap = FindParentMap(element)) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
element.SetValue(ParentMapProperty, parentMap);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return parentMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-30 23:13:50 +02:00
|
|
|
|
private static MapBase FindParentMap(FrameworkElement element)
|
2012-11-23 16:16:09 +01:00
|
|
|
|
{
|
2020-04-16 23:15:03 +02:00
|
|
|
|
return VisualTreeHelper.GetParent(element) is FrameworkElement parent
|
|
|
|
|
|
? ((parent as MapBase) ?? (MapBase)element.GetValue(ParentMapProperty) ?? FindParentMap(parent))
|
|
|
|
|
|
: null;
|
2012-11-23 16:16:09 +01:00
|
|
|
|
}
|
2018-04-30 23:13:50 +02:00
|
|
|
|
|
2020-03-28 21:53:38 +01:00
|
|
|
|
private static void SetViewPosition(FrameworkElement element, Point? viewPosition)
|
2018-04-30 23:13:50 +02:00
|
|
|
|
{
|
2020-03-28 21:53:38 +01:00
|
|
|
|
element.SetValue(ViewPositionProperty, viewPosition);
|
2018-04-30 23:13:50 +02:00
|
|
|
|
}
|
2012-11-23 16:16:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|