mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Update MapLayerMenuItem.cs
This commit is contained in:
parent
62ffed2caf
commit
fedf5eba12
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#if WPF
|
#if WPF
|
||||||
|
|
@ -24,40 +24,39 @@ namespace MapControl.UiTools
|
||||||
#endif
|
#endif
|
||||||
public partial 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
|
#if AVALONIA
|
||||||
[Content]
|
[Content]
|
||||||
#endif
|
#endif
|
||||||
public FrameworkElement MapLayer { get; set; }
|
public FrameworkElement MapLayer { get; set; }
|
||||||
|
|
||||||
public string SourcePath { get; set; }
|
|
||||||
|
|
||||||
public override bool GetIsChecked(MapBase map)
|
public override bool GetIsChecked(MapBase map)
|
||||||
{
|
{
|
||||||
return MapLayer != null && map.Children.Contains(MapLayer);
|
return MapLayer != null && map.Children.Contains(MapLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task ExecuteAsync(MapBase map)
|
public override Task ExecuteAsync(MapBase map)
|
||||||
{
|
{
|
||||||
MapLayer ??= await MapLayerFactory?.Invoke(SourcePath);
|
|
||||||
|
|
||||||
if (MapLayer != null)
|
if (MapLayer != null)
|
||||||
{
|
{
|
||||||
map.MapLayer = MapLayer;
|
map.MapLayer = MapLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class MapOverlayMenuItem : MapLayerMenuItem
|
public partial class MapOverlayMenuItem : MapLayerMenuItem
|
||||||
{
|
{
|
||||||
|
public string SourcePath { get; set; }
|
||||||
|
|
||||||
public int InsertOrder { get; set; }
|
public int InsertOrder { get; set; }
|
||||||
|
|
||||||
public override async Task ExecuteAsync(MapBase map)
|
public override async Task ExecuteAsync(MapBase map)
|
||||||
{
|
{
|
||||||
MapLayer ??= await MapLayerFactory?.Invoke(SourcePath);
|
if (MapLayer == null)
|
||||||
|
{
|
||||||
|
await CreateMapLayer();
|
||||||
|
}
|
||||||
|
|
||||||
if (MapLayer != null)
|
if (MapLayer != null)
|
||||||
{
|
{
|
||||||
|
|
@ -81,5 +80,19 @@ namespace MapControl.UiTools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual async Task CreateMapLayer()
|
||||||
|
{
|
||||||
|
var ext = Path.GetExtension(SourcePath).ToLower();
|
||||||
|
|
||||||
|
if (ext == ".kmz" || ext == ".kml")
|
||||||
|
{
|
||||||
|
MapLayer = await GroundOverlay.CreateAsync(SourcePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MapLayer = await GeoImage.CreateAsync(SourcePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue