2025-02-27 18:46:32 +01:00
|
|
|
|
#if WPF
|
2024-05-22 11:25:32 +02:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Media;
|
2023-01-19 17:16:02 +01:00
|
|
|
|
#elif UWP
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#elif WINUI
|
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
|
|
|
|
|
using Microsoft.UI.Xaml.Media;
|
2023-01-19 17:16:02 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2024-07-05 09:20:30 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
|
2023-01-19 17:16:02 +01:00
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Container class for an item in a MapItemsControl.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class MapItem : ListBoxItem, IMapElement
|
|
|
|
|
|
{
|
|
|
|
|
|
private MapBase parentMap;
|
|
|
|
|
|
private MatrixTransform mapTransform;
|
|
|
|
|
|
|
|
|
|
|
|
/// <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 => parentMap;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parentMap != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parentMap.ViewportChanged -= OnViewportChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parentMap = value;
|
|
|
|
|
|
|
|
|
|
|
|
if (parentMap != null && mapTransform != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Attach ViewportChanged handler only if MapTransform is actually used.
|
|
|
|
|
|
//
|
|
|
|
|
|
parentMap.ViewportChanged += OnViewportChanged;
|
2025-01-27 16:56:35 +01:00
|
|
|
|
|
2025-06-07 15:08:36 +02:00
|
|
|
|
UpdateMapTransform();
|
2023-01-19 17:16:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a Transform for scaling and rotating geometries
|
|
|
|
|
|
/// in map coordinates (meters) to view coordinates (pixels).
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Transform MapTransform
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mapTransform == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mapTransform = new MatrixTransform();
|
|
|
|
|
|
|
|
|
|
|
|
if (parentMap != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parentMap.ViewportChanged += OnViewportChanged;
|
2025-01-27 16:56:35 +01:00
|
|
|
|
|
2025-06-07 15:08:36 +02:00
|
|
|
|
UpdateMapTransform();
|
2023-01-19 17:16:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mapTransform;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
|
|
|
|
|
{
|
2025-06-07 15:08:36 +02:00
|
|
|
|
UpdateMapTransform();
|
2023-01-19 17:16:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-07 15:08:36 +02:00
|
|
|
|
private void UpdateMapTransform()
|
2023-01-19 17:16:02 +01:00
|
|
|
|
{
|
2025-06-07 15:08:36 +02:00
|
|
|
|
if (mapTransform != null && parentMap != null && Location != null)
|
2023-01-19 17:16:02 +01:00
|
|
|
|
{
|
2025-06-07 15:08:36 +02:00
|
|
|
|
mapTransform.Matrix = parentMap.GetMapTransform(Location);
|
2023-01-19 17:16:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|