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
|
2025-09-17 22:25:50 +02:00
|
|
|
|
public partial class MapLayerMenuItem : MapMenuItem
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-17 22:25:50 +02:00
|
|
|
|
public static Func<string, Task<FrameworkElement>> MapLayerFactory { get; set; } =
|
|
|
|
|
|
async sourcePath => sourcePath.EndsWith(".kmz") || sourcePath.EndsWith(".kml")
|
|
|
|
|
|
? (FrameworkElement)await GroundOverlay.CreateAsync(sourcePath)
|
|
|
|
|
|
: (FrameworkElement)await GeoImage.CreateAsync(sourcePath);
|
2025-03-21 17:22:07 +01:00
|
|
|
|
#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
|
|
|
|
|
2025-09-17 22:25:50 +02:00
|
|
|
|
public string SourcePath { get; set; }
|
2025-03-21 17:22:07 +01:00
|
|
|
|
|
2025-09-17 22:25:50 +02:00
|
|
|
|
public override bool GetIsChecked(MapBase map)
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-08 17:47:57 +02:00
|
|
|
|
return MapLayer != null && map.Children.Contains(MapLayer);
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 22:25:50 +02:00
|
|
|
|
public override async Task ExecuteAsync(MapBase map)
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-17 22:25:50 +02:00
|
|
|
|
MapLayer ??= await MapLayerFactory?.Invoke(SourcePath);
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 22:25:50 +02:00
|
|
|
|
public partial class MapOverlayMenuItem : MapLayerMenuItem
|
2025-03-21 17:22:07 +01:00
|
|
|
|
{
|
2025-09-17 10:04:34 +02:00
|
|
|
|
public int InsertOrder { get; set; }
|
|
|
|
|
|
|
2025-09-17 22:25:50 +02:00
|
|
|
|
public override async Task ExecuteAsync(MapBase map)
|
2025-09-17 10:04:34 +02:00
|
|
|
|
{
|
2025-09-17 22:25:50 +02:00
|
|
|
|
MapLayer ??= await MapLayerFactory?.Invoke(SourcePath);
|
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
|
|
|
|
|
|
{
|
2025-09-08 17:47:57 +02:00
|
|
|
|
var insertIndex = ParentMenuItems
|
2025-03-21 18:48:33 +01:00
|
|
|
|
.OfType<MapOverlayMenuItem>()
|
2025-09-08 17:47:57 +02:00
|
|
|
|
.Where(item => item.InsertOrder <= InsertOrder && item.GetIsChecked(map))
|
|
|
|
|
|
.Count();
|
2025-03-21 18:48:33 +01:00
|
|
|
|
|
2025-09-08 17:47:57 +02:00
|
|
|
|
if (map.MapLayer != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
insertIndex++;
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
2025-09-08 17:47:57 +02:00
|
|
|
|
|
|
|
|
|
|
map.Children.Insert(insertIndex, MapLayer);
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
2025-03-21 18:48:33 +01:00
|
|
|
|
}
|
2025-03-21 17:22:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|