mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-11 19:19:59 +01:00
104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
#if WPF
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
#elif UWP
|
|
using Windows.UI.Xaml.Controls;
|
|
using Windows.UI.Xaml.Media;
|
|
#elif WINUI
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Media;
|
|
#elif AVALONIA
|
|
using Avalonia.Controls;
|
|
using Avalonia.Media;
|
|
#endif
|
|
|
|
namespace MapControl
|
|
{
|
|
/// <summary>
|
|
/// Container class for an item in a MapItemsControl.
|
|
/// </summary>
|
|
public partial class MapItem : ListBoxItem, IMapElement
|
|
{
|
|
/// <summary>
|
|
/// Gets/sets MapPanel.AutoCollapse.
|
|
/// </summary>
|
|
public bool AutoCollapse
|
|
{
|
|
get => (bool)GetValue(AutoCollapseProperty);
|
|
set => SetValue(AutoCollapseProperty, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets/sets MapPanel.Location.
|
|
/// </summary>
|
|
public Location Location
|
|
{
|
|
get => (Location)GetValue(LocationProperty);
|
|
set => SetValue(LocationProperty, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Implements IMapElement.ParentMap.
|
|
/// </summary>
|
|
public MapBase ParentMap
|
|
{
|
|
get;
|
|
set
|
|
{
|
|
if (field != null)
|
|
{
|
|
field.ViewportChanged -= OnViewportChanged;
|
|
}
|
|
|
|
field = value;
|
|
|
|
if (field != null && MapTransform != null)
|
|
{
|
|
// Attach ViewportChanged handler only if MapTransform is actually used.
|
|
//
|
|
field.ViewportChanged += OnViewportChanged;
|
|
|
|
UpdateMapTransform();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a Transform for scaling and rotating geometries
|
|
/// in map coordinates (meters) to view coordinates (pixels).
|
|
/// </summary>
|
|
public MatrixTransform MapTransform
|
|
{
|
|
get
|
|
{
|
|
if (field == null)
|
|
{
|
|
field = new MatrixTransform();
|
|
|
|
if (ParentMap != null)
|
|
{
|
|
ParentMap.ViewportChanged += OnViewportChanged;
|
|
|
|
UpdateMapTransform();
|
|
}
|
|
}
|
|
|
|
return field;
|
|
}
|
|
}
|
|
|
|
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
|
{
|
|
UpdateMapTransform();
|
|
}
|
|
|
|
private void UpdateMapTransform()
|
|
{
|
|
if (MapTransform != null && ParentMap != null && Location != null)
|
|
{
|
|
MapTransform.Matrix = ParentMap.GetMapTransform(Location);
|
|
}
|
|
}
|
|
}
|
|
}
|