mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
ParentMap property initialization
This commit is contained in:
parent
6a9b622793
commit
207565feba
|
|
@ -26,13 +26,6 @@ namespace MapControl
|
|||
new PropertyMetadata(null, (o, e) => BindingOperations.SetBinding(
|
||||
o, LocationProperty, new Binding { Path = new PropertyPath((string)e.NewValue) })));
|
||||
|
||||
public MapItem()
|
||||
{
|
||||
DefaultStyleKey = typeof(MapItem);
|
||||
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets MapPanel.AutoCollapse.
|
||||
/// </summary>
|
||||
|
|
@ -66,13 +59,6 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public partial class MapItemsControl : ListBox
|
||||
{
|
||||
public MapItemsControl()
|
||||
{
|
||||
DefaultStyleKey = typeof(MapItemsControl);
|
||||
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride()
|
||||
{
|
||||
return new MapItem();
|
||||
|
|
|
|||
|
|
@ -42,11 +42,6 @@ namespace MapControl
|
|||
set { SetParentMap(value); }
|
||||
}
|
||||
|
||||
public MapPanel()
|
||||
{
|
||||
InitMapElement(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value that controls whether an element's Visibility is automatically
|
||||
/// set to Collapsed when it is located outside the visible viewport area.
|
||||
|
|
|
|||
|
|
@ -24,11 +24,6 @@ namespace MapControl
|
|||
|
||||
private MapBase parentMap;
|
||||
|
||||
public MapPath()
|
||||
{
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a Location that is used as
|
||||
/// - either the origin point of a geometry specified in cartesian map units (meters)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,9 @@ namespace MapControl
|
|||
updateTimer = new DispatcherTimer { Interval = UpdateInterval };
|
||||
updateTimer.Tick += (s, e) => Update(false);
|
||||
|
||||
#if WINDOWS_UWP
|
||||
MapPanel.InitMapElement(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
public ITileImageLoader TileImageLoader { get; }
|
||||
|
|
|
|||
|
|
@ -131,9 +131,6 @@
|
|||
<Compile Include="..\Shared\OrthographicProjection.cs">
|
||||
<Link>OrthographicProjection.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\Pushpin.cs">
|
||||
<Link>Pushpin.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\StereographicProjection.cs">
|
||||
<Link>StereographicProjection.cs</Link>
|
||||
</Compile>
|
||||
|
|
@ -198,6 +195,7 @@
|
|||
<Compile Include="Matrix.UWP.cs" />
|
||||
<Compile Include="Point.UWP.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Pushpin.cs" />
|
||||
<Compile Include="Tile.UWP.cs" />
|
||||
<Compile Include="TileImageLoader.UWP.cs" />
|
||||
<Compile Include="ImageLoader.UWP.cs" />
|
||||
|
|
|
|||
|
|
@ -19,6 +19,12 @@ namespace MapControl
|
|||
nameof(Location), typeof(Location), typeof(MapItem),
|
||||
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((MapItem)o, (Location)e.NewValue)));
|
||||
|
||||
public MapItem()
|
||||
{
|
||||
DefaultStyleKey = typeof(MapItem);
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
protected override void OnPointerPressed(PointerRoutedEventArgs e)
|
||||
{
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
|
||||
|
|
@ -28,6 +34,12 @@ namespace MapControl
|
|||
|
||||
public partial class MapItemsControl
|
||||
{
|
||||
public MapItemsControl()
|
||||
{
|
||||
DefaultStyleKey = typeof(MapItemsControl);
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
public new FrameworkElement ContainerFromItem(object item)
|
||||
{
|
||||
return (FrameworkElement)base.ContainerFromItem(item);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ namespace MapControl
|
|||
private static readonly DependencyProperty ViewPositionProperty = DependencyProperty.RegisterAttached(
|
||||
"ViewPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata(null));
|
||||
|
||||
public MapPanel()
|
||||
{
|
||||
InitMapElement(this);
|
||||
}
|
||||
|
||||
public static void InitMapElement(FrameworkElement element)
|
||||
{
|
||||
if (element is MapBase)
|
||||
|
|
@ -31,7 +36,7 @@ namespace MapControl
|
|||
}
|
||||
else
|
||||
{
|
||||
// Workaround for missing property value inheritance in Windows Runtime.
|
||||
// Workaround for missing property value inheritance in UWP.
|
||||
// Loaded and Unloaded handlers set and clear the ParentMap property value.
|
||||
|
||||
element.Loaded += (s, e) => GetParentMap(element);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ namespace MapControl
|
|||
{
|
||||
public partial class MapPath : Path
|
||||
{
|
||||
public MapPath()
|
||||
{
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
#region Methods used only by derived classes MapPolyline and MapPolygon
|
||||
|
||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,8 @@
|
|||
// © 2021 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
@ -17,7 +12,6 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public class Pushpin : ContentControl
|
||||
{
|
||||
#if WINDOWS_UWP
|
||||
public static readonly DependencyProperty AutoCollapseProperty = DependencyProperty.Register(
|
||||
nameof(AutoCollapse), typeof(bool), typeof(Pushpin),
|
||||
new PropertyMetadata(false, (o, e) => MapPanel.SetAutoCollapse((Pushpin)o, (bool)e.NewValue)));
|
||||
|
|
@ -25,15 +19,10 @@ namespace MapControl
|
|||
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
|
||||
nameof(Location), typeof(Location), typeof(Pushpin),
|
||||
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((Pushpin)o, (Location)e.NewValue)));
|
||||
#else
|
||||
public static readonly DependencyProperty AutoCollapseProperty = MapPanel.AutoCollapseProperty.AddOwner(typeof(Pushpin));
|
||||
|
||||
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(Pushpin));
|
||||
#endif
|
||||
public Pushpin()
|
||||
{
|
||||
DefaultStyleKey = typeof(Pushpin);
|
||||
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
|
|
@ -15,6 +15,11 @@ namespace MapControl
|
|||
|
||||
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(MapItem));
|
||||
|
||||
static MapItem()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem)));
|
||||
}
|
||||
|
||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
|
||||
|
|
@ -24,6 +29,11 @@ namespace MapControl
|
|||
|
||||
public partial class MapItemsControl
|
||||
{
|
||||
static MapItemsControl()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItemsControl), new FrameworkPropertyMetadata(typeof(MapItemsControl)));
|
||||
}
|
||||
|
||||
public FrameworkElement ContainerFromItem(object item)
|
||||
{
|
||||
return (FrameworkElement)ItemContainerGenerator.ContainerFromItem(item);
|
||||
|
|
|
|||
|
|
@ -26,19 +26,19 @@ namespace MapControl
|
|||
public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty;
|
||||
public static readonly DependencyProperty ViewPositionProperty = ViewPositionPropertyKey.DependencyProperty;
|
||||
|
||||
public MapPanel()
|
||||
{
|
||||
if (this is MapBase)
|
||||
{
|
||||
SetValue(ParentMapPropertyKey, this);
|
||||
}
|
||||
}
|
||||
|
||||
public static MapBase GetParentMap(FrameworkElement element)
|
||||
{
|
||||
return (MapBase)element.GetValue(ParentMapProperty);
|
||||
}
|
||||
|
||||
public static void InitMapElement(FrameworkElement element)
|
||||
{
|
||||
if (element is MapBase)
|
||||
{
|
||||
element.SetValue(ParentMapPropertyKey, element);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetViewPosition(FrameworkElement element, Point? viewPosition)
|
||||
{
|
||||
element.SetValue(ViewPositionPropertyKey, viewPosition);
|
||||
|
|
|
|||
42
MapControl/WPF/Pushpin.cs
Normal file
42
MapControl/WPF/Pushpin.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2021 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Pushpin at a geographic location specified by the Location property.
|
||||
/// </summary>
|
||||
public class Pushpin : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty AutoCollapseProperty = MapPanel.AutoCollapseProperty.AddOwner(typeof(Pushpin));
|
||||
|
||||
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(Pushpin));
|
||||
|
||||
static Pushpin()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets MapPanel.AutoCollapse.
|
||||
/// </summary>
|
||||
public bool AutoCollapse
|
||||
{
|
||||
get { return (bool)GetValue(AutoCollapseProperty); }
|
||||
set { SetValue(AutoCollapseProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets MapPanel.Location.
|
||||
/// </summary>
|
||||
public Location Location
|
||||
{
|
||||
get { return (Location)GetValue(LocationProperty); }
|
||||
set { SetValue(LocationProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue