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
|
||||
[Content]
|
||||
#endif
|
||||
public virtual FrameworkElement MapLayer { get; set; }
|
||||
public FrameworkElement MapLayer { get; set; }
|
||||
|
||||
public Func<Task<FrameworkElement>> MapLayerFactory { get; set; }
|
||||
|
||||
|
|
@ -38,12 +38,14 @@ namespace MapControl.UiTools
|
|||
|
||||
public override async Task Execute(MapBase map)
|
||||
{
|
||||
var layer = MapLayer ?? (MapLayer = await MapLayerFactory.Invoke());
|
||||
|
||||
if (layer != null)
|
||||
if (MapLayer == null)
|
||||
{
|
||||
map.MapLayer = layer;
|
||||
IsChecked = true;
|
||||
MapLayer = await MapLayerFactory?.Invoke();
|
||||
}
|
||||
|
||||
if (MapLayer != null)
|
||||
{
|
||||
map.MapLayer = MapLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -52,37 +54,38 @@ namespace MapControl.UiTools
|
|||
{
|
||||
public override async Task Execute(MapBase map)
|
||||
{
|
||||
var layer = MapLayer ?? (MapLayer = await MapLayerFactory.Invoke());
|
||||
|
||||
if (layer != null)
|
||||
if (MapLayer == null)
|
||||
{
|
||||
if (map.Children.Contains(layer))
|
||||
MapLayer = await MapLayerFactory?.Invoke();
|
||||
}
|
||||
|
||||
if (MapLayer != null)
|
||||
{
|
||||
if (map.Children.Contains(MapLayer))
|
||||
{
|
||||
map.Children.Remove(layer);
|
||||
map.Children.Remove(MapLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
var index = 1;
|
||||
|
||||
foreach (var itemLayer in ParentMenuItems
|
||||
foreach (var mapLayer in ParentMenuItems
|
||||
.OfType<MapOverlayMenuItem>()
|
||||
.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;
|
||||
}
|
||||
|
||||
if (map.Children.Contains(itemLayer))
|
||||
if (map.Children.Contains(mapLayer))
|
||||
{
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IsChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,28 +27,23 @@ namespace MapControl.UiTools
|
|||
|
||||
protected override bool GetIsChecked(MapBase map)
|
||||
{
|
||||
return map.MapProjection.CrsId == MapProjection;
|
||||
return map.MapProjection.ToString() == MapProjection;
|
||||
}
|
||||
|
||||
public override Task Execute(MapBase map)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
if (map.MapProjection.CrsId != MapProjection)
|
||||
if (!GetIsChecked(map))
|
||||
{
|
||||
try
|
||||
{
|
||||
map.MapProjection = MapProjectionFactory.Instance.GetProjection(MapProjection);
|
||||
map.MapProjection = MapControl.MapProjection.Parse(MapProjection);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(MapProjectionFactory)}: {ex.Message}");
|
||||
success = false;
|
||||
Debug.WriteLine($"MapProjection.Parse: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
IsChecked = success;
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue