2025-03-21 17:22:07 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
#if WPF
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Markup;
|
|
|
|
|
|
#elif UWP
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Markup;
|
|
|
|
|
|
#elif WINUI
|
|
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
|
using Microsoft.UI.Xaml.Markup;
|
|
|
|
|
|
#else
|
|
|
|
|
|
using Avalonia.Metadata;
|
|
|
|
|
|
using FrameworkElement = Avalonia.Controls.Control;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl.UiTools
|
|
|
|
|
|
{
|
|
|
|
|
|
#if WPF
|
|
|
|
|
|
[ContentProperty(nameof(MapLayer))]
|
|
|
|
|
|
#elif UWP || WINUI
|
|
|
|
|
|
[ContentProperty(Name = nameof(MapLayer))]
|
|
|
|
|
|
#endif
|
|
|
|
|
|
public class MapLayerMenuItem : MapMenuItem
|
|
|
|
|
|
{
|
|
|
|
|
|
#if AVALONIA
|
|
|
|
|
|
[Content]
|
|
|
|
|
|
#endif
|
2025-09-06 12:25:47 +02:00
|
|
|
|
public FrameworkElement MapLayer { get; set; }
|
2025-03-21 17:22:07 +01:00
|
|
|
|
|
|
|
|
|
|
public Func<Task<FrameworkElement>> MapLayerFactory { get; set; }
|
|
|
|
|
|
|
2025-03-26 19:58:47 +01:00
|
|
|
|
protected override bool GetIsChecked(MapBase map)
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-03-26 19:58:47 +01:00
|
|
|
|
return map.Children.Contains(MapLayer);
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-21 18:48:33 +01:00
|
|
|
|
public override async Task Execute(MapBase map)
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-06 12:25:47 +02:00
|
|
|
|
if (MapLayer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
MapLayer = await MapLayerFactory?.Invoke();
|
|
|
|
|
|
}
|
2025-03-21 18:03:57 +01:00
|
|
|
|
|
2025-09-06 12:25:47 +02:00
|
|
|
|
if (MapLayer != null)
|
2025-03-21 18:03:57 +01:00
|
|
|
|
{
|
2025-09-06 12:25:47 +02:00
|
|
|
|
map.MapLayer = MapLayer;
|
2025-03-21 18:03:57 +01:00
|
|
|
|
}
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class MapOverlayMenuItem : MapLayerMenuItem
|
|
|
|
|
|
{
|
2025-03-21 18:48:33 +01:00
|
|
|
|
public override async Task Execute(MapBase map)
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-06 12:25:47 +02:00
|
|
|
|
if (MapLayer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
MapLayer = await MapLayerFactory?.Invoke();
|
|
|
|
|
|
}
|
2025-03-21 17:22:07 +01:00
|
|
|
|
|
2025-09-06 12:25:47 +02:00
|
|
|
|
if (MapLayer != null)
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-06 12:25:47 +02:00
|
|
|
|
if (map.Children.Contains(MapLayer))
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-06 12:25:47 +02:00
|
|
|
|
map.Children.Remove(MapLayer);
|
2025-03-21 18:48:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var index = 1;
|
2025-03-21 17:22:07 +01:00
|
|
|
|
|
2025-09-06 12:25:47 +02:00
|
|
|
|
foreach (var mapLayer in ParentMenuItems
|
2025-03-21 18:48:33 +01:00
|
|
|
|
.OfType<MapOverlayMenuItem>()
|
|
|
|
|
|
.Select(item => item.MapLayer)
|
2025-09-06 12:25:47 +02:00
|
|
|
|
.Where(mapLayer => mapLayer != null))
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-06 12:25:47 +02:00
|
|
|
|
if (mapLayer == MapLayer)
|
2025-03-21 18:48:33 +01:00
|
|
|
|
{
|
2025-09-06 12:25:47 +02:00
|
|
|
|
map.Children.Insert(index, mapLayer);
|
2025-03-21 18:48:33 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-06 12:25:47 +02:00
|
|
|
|
if (map.Children.Contains(mapLayer))
|
2025-03-21 18:48:33 +01:00
|
|
|
|
{
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-21 18:48:33 +01:00
|
|
|
|
}
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|