2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2018-02-09 17:43:47 +01:00
|
|
|
|
// © 2018 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
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly DependencyProperty ParentMapProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"ParentMap", typeof(MapBase), typeof(MapPanel), new PropertyMetadata(null, ParentMapPropertyChanged));
|
|
|
|
|
|
|
2018-04-30 23:13:50 +02:00
|
|
|
|
private static readonly DependencyProperty ViewportPositionProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"ViewportPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata(null));
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-04-30 23:13:50 +02:00
|
|
|
|
var parent = VisualTreeHelper.GetParent(element) as FrameworkElement;
|
2012-11-23 16:16:09 +01:00
|
|
|
|
|
2017-09-05 20:57:17 +02:00
|
|
|
|
return parent == null ? null
|
|
|
|
|
|
: ((parent as MapBase)
|
|
|
|
|
|
?? (MapBase)element.GetValue(ParentMapProperty)
|
|
|
|
|
|
?? FindParentMap(parent));
|
2012-11-23 16:16:09 +01:00
|
|
|
|
}
|
2018-04-30 23:13:50 +02:00
|
|
|
|
|
|
|
|
|
|
private static void SetViewportPosition(FrameworkElement element, Point? viewportPosition)
|
|
|
|
|
|
{
|
|
|
|
|
|
element.SetValue(ViewportPositionProperty, viewportPosition);
|
|
|
|
|
|
}
|
2012-11-23 16:16:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|