mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
MapMenuItems
This commit is contained in:
parent
ac97d2f7ed
commit
acecccf381
|
|
@ -27,7 +27,7 @@ namespace MapControl.UiTools
|
||||||
#if AVALONIA
|
#if AVALONIA
|
||||||
[Content]
|
[Content]
|
||||||
#endif
|
#endif
|
||||||
public virtual FrameworkElement MapLayer { get; set; }
|
public FrameworkElement MapLayer { get; set; }
|
||||||
|
|
||||||
public Func<Task<FrameworkElement>> MapLayerFactory { get; set; }
|
public Func<Task<FrameworkElement>> MapLayerFactory { get; set; }
|
||||||
|
|
||||||
|
|
@ -38,12 +38,14 @@ namespace MapControl.UiTools
|
||||||
|
|
||||||
public override async Task Execute(MapBase map)
|
public override async Task Execute(MapBase map)
|
||||||
{
|
{
|
||||||
var layer = MapLayer ?? (MapLayer = await MapLayerFactory.Invoke());
|
if (MapLayer == null)
|
||||||
|
|
||||||
if (layer != null)
|
|
||||||
{
|
{
|
||||||
map.MapLayer = layer;
|
MapLayer = await MapLayerFactory?.Invoke();
|
||||||
IsChecked = true;
|
}
|
||||||
|
|
||||||
|
if (MapLayer != null)
|
||||||
|
{
|
||||||
|
map.MapLayer = MapLayer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,37 +54,38 @@ namespace MapControl.UiTools
|
||||||
{
|
{
|
||||||
public override async Task Execute(MapBase map)
|
public override async Task Execute(MapBase map)
|
||||||
{
|
{
|
||||||
var layer = MapLayer ?? (MapLayer = await MapLayerFactory.Invoke());
|
if (MapLayer == null)
|
||||||
|
{
|
||||||
|
MapLayer = await MapLayerFactory?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
if (layer != null)
|
if (MapLayer != null)
|
||||||
{
|
{
|
||||||
if (map.Children.Contains(layer))
|
if (map.Children.Contains(MapLayer))
|
||||||
{
|
{
|
||||||
map.Children.Remove(layer);
|
map.Children.Remove(MapLayer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var index = 1;
|
var index = 1;
|
||||||
|
|
||||||
foreach (var itemLayer in ParentMenuItems
|
foreach (var mapLayer in ParentMenuItems
|
||||||
.OfType<MapOverlayMenuItem>()
|
.OfType<MapOverlayMenuItem>()
|
||||||
.Select(item => item.MapLayer)
|
.Select(item => item.MapLayer)
|
||||||
.Where(itemLayer => itemLayer != null))
|
.Where(mapLayer => mapLayer != null))
|
||||||
{
|
{
|
||||||
if (itemLayer == layer)
|
if (mapLayer == MapLayer)
|
||||||
{
|
{
|
||||||
map.Children.Insert(index, itemLayer);
|
map.Children.Insert(index, mapLayer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.Children.Contains(itemLayer))
|
if (map.Children.Contains(mapLayer))
|
||||||
{
|
{
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IsChecked = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,28 +27,23 @@ namespace MapControl.UiTools
|
||||||
|
|
||||||
protected override bool GetIsChecked(MapBase map)
|
protected override bool GetIsChecked(MapBase map)
|
||||||
{
|
{
|
||||||
return map.MapProjection.CrsId == MapProjection;
|
return map.MapProjection.ToString() == MapProjection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task Execute(MapBase map)
|
public override Task Execute(MapBase map)
|
||||||
{
|
{
|
||||||
bool success = true;
|
if (!GetIsChecked(map))
|
||||||
|
|
||||||
if (map.MapProjection.CrsId != MapProjection)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
map.MapProjection = MapProjectionFactory.Instance.GetProjection(MapProjection);
|
map.MapProjection = MapControl.MapProjection.Parse(MapProjection);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{nameof(MapProjectionFactory)}: {ex.Message}");
|
Debug.WriteLine($"MapProjection.Parse: {ex.Message}");
|
||||||
success = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IsChecked = success;
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue