mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Static MapLayerMenuItem.MapLayerFactory
This commit is contained in:
parent
5afea53c7c
commit
62ffed2caf
|
|
@ -10,6 +10,10 @@ namespace MapControl.UiTools
|
|||
{
|
||||
public abstract partial class MapMenuItem : MenuItem
|
||||
{
|
||||
public abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task ExecuteAsync(MapBase map);
|
||||
|
||||
protected MapMenuItem()
|
||||
{
|
||||
Icon = new TextBlock
|
||||
|
|
@ -31,7 +35,7 @@ namespace MapControl.UiTools
|
|||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
await Execute(map);
|
||||
await ExecuteAsync(map);
|
||||
|
||||
foreach (var item in ParentMenuItems)
|
||||
{
|
||||
|
|
@ -51,10 +55,6 @@ namespace MapControl.UiTools
|
|||
|
||||
protected override Type StyleKeyOverride => typeof(MenuItem);
|
||||
|
||||
protected abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task Execute(MapBase map);
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs args)
|
||||
{
|
||||
base.OnPropertyChanged(args);
|
||||
|
|
|
|||
|
|
@ -22,23 +22,27 @@ namespace MapControl.UiTools
|
|||
#elif UWP || WINUI
|
||||
[ContentProperty(Name = nameof(MapLayer))]
|
||||
#endif
|
||||
public class MapLayerMenuItem : MapMenuItem
|
||||
public partial class MapLayerMenuItem : MapMenuItem
|
||||
{
|
||||
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);
|
||||
#if AVALONIA
|
||||
[Content]
|
||||
#endif
|
||||
public FrameworkElement MapLayer { get; set; }
|
||||
|
||||
public Func<Task<FrameworkElement>> MapLayerFactory { get; set; }
|
||||
public string SourcePath { get; set; }
|
||||
|
||||
protected override bool GetIsChecked(MapBase map)
|
||||
public override bool GetIsChecked(MapBase map)
|
||||
{
|
||||
return MapLayer != null && map.Children.Contains(MapLayer);
|
||||
}
|
||||
|
||||
public override async Task Execute(MapBase map)
|
||||
public override async Task ExecuteAsync(MapBase map)
|
||||
{
|
||||
MapLayer ??= await MapLayerFactory?.Invoke();
|
||||
MapLayer ??= await MapLayerFactory?.Invoke(SourcePath);
|
||||
|
||||
if (MapLayer != null)
|
||||
{
|
||||
|
|
@ -47,33 +51,13 @@ namespace MapControl.UiTools
|
|||
}
|
||||
}
|
||||
|
||||
public class MapOverlayMenuItem : MapLayerMenuItem
|
||||
public partial class MapOverlayMenuItem : MapLayerMenuItem
|
||||
{
|
||||
private string sourcePath;
|
||||
|
||||
public string SourcePath
|
||||
{
|
||||
get => sourcePath;
|
||||
set
|
||||
{
|
||||
sourcePath = value;
|
||||
|
||||
if (sourcePath.EndsWith(".kmz") || sourcePath.EndsWith(".kml"))
|
||||
{
|
||||
MapLayerFactory = async () => await GroundOverlay.CreateAsync(sourcePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
MapLayerFactory = async () => await GeoImage.CreateAsync(sourcePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int InsertOrder { get; set; }
|
||||
|
||||
public override async Task Execute(MapBase map)
|
||||
public override async Task ExecuteAsync(MapBase map)
|
||||
{
|
||||
MapLayer ??= await MapLayerFactory?.Invoke();
|
||||
MapLayer ??= await MapLayerFactory?.Invoke(SourcePath);
|
||||
|
||||
if (MapLayer != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,19 +18,19 @@ namespace MapControl.UiTools
|
|||
#elif UWP || WINUI
|
||||
[ContentProperty(Name = nameof(MapProjection))]
|
||||
#endif
|
||||
public class MapProjectionMenuItem : MapMenuItem
|
||||
public partial class MapProjectionMenuItem : MapMenuItem
|
||||
{
|
||||
#if AVALONIA
|
||||
[Content]
|
||||
#endif
|
||||
public string MapProjection { get; set; }
|
||||
|
||||
protected override bool GetIsChecked(MapBase map)
|
||||
public override bool GetIsChecked(MapBase map)
|
||||
{
|
||||
return map.MapProjection.ToString() == MapProjection;
|
||||
}
|
||||
|
||||
public override Task Execute(MapBase map)
|
||||
public override Task ExecuteAsync(MapBase map)
|
||||
{
|
||||
if (!GetIsChecked(map))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ namespace MapControl.UiTools
|
|||
|
||||
if (initialItem != null)
|
||||
{
|
||||
await initialItem.Execute(Map);
|
||||
initialItem.IsChecked = true;
|
||||
|
||||
await initialItem.ExecuteAsync(Map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ using System.Windows.Controls;
|
|||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
public abstract class MapMenuItem : MenuItem
|
||||
public abstract partial class MapMenuItem : MenuItem
|
||||
{
|
||||
public abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task ExecuteAsync(MapBase map);
|
||||
|
||||
protected MapMenuItem()
|
||||
{
|
||||
Loaded += (s, e) =>
|
||||
|
|
@ -21,7 +25,7 @@ namespace MapControl.UiTools
|
|||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
await Execute(map);
|
||||
await ExecuteAsync(map);
|
||||
|
||||
foreach (var item in ParentMenuItems)
|
||||
{
|
||||
|
|
@ -38,9 +42,5 @@ namespace MapControl.UiTools
|
|||
}
|
||||
|
||||
protected IEnumerable<MapMenuItem> ParentMenuItems => ((ItemsControl)Parent).Items.OfType<MapMenuItem>();
|
||||
|
||||
protected abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task Execute(MapBase map);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,12 @@ using Microsoft.UI.Xaml.Media;
|
|||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
public abstract class MapMenuItem : ToggleMenuFlyoutItem
|
||||
public abstract partial class MapMenuItem : ToggleMenuFlyoutItem
|
||||
{
|
||||
public abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task ExecuteAsync(MapBase map);
|
||||
|
||||
protected MapMenuItem()
|
||||
{
|
||||
Loaded += (s, e) =>
|
||||
|
|
@ -29,7 +33,7 @@ namespace MapControl.UiTools
|
|||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
await Execute(map);
|
||||
await ExecuteAsync(map);
|
||||
|
||||
foreach (var item in ParentMenuItems)
|
||||
{
|
||||
|
|
@ -40,9 +44,5 @@ namespace MapControl.UiTools
|
|||
}
|
||||
|
||||
protected IList<MapMenuItem> ParentMenuItems { get; private set; }
|
||||
|
||||
protected abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task Execute(MapBase map);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue