Added MapBase.MapLayerItemsSource property

This commit is contained in:
ClemensFischer 2025-08-11 23:01:22 +02:00
parent 0b5d1e439f
commit 2194f08a74
6 changed files with 275 additions and 70 deletions

View file

@ -12,12 +12,6 @@ using Microsoft.UI.Xaml.Media;
namespace MapControl
{
public interface IMapLayer : IMapElement
{
Brush MapBackground { get; }
Brush MapForeground { get; }
}
/// <summary>
/// The map control. Displays map content provided by one or more tile or image layers,
/// such as MapTileLayerBase or MapImageLayer instances.
@ -42,10 +36,6 @@ namespace MapControl
public static readonly DependencyProperty AnimationDurationProperty =
DependencyPropertyHelper.Register<MapBase, TimeSpan>(nameof(AnimationDuration), TimeSpan.FromSeconds(0.3));
public static readonly DependencyProperty MapLayerProperty =
DependencyPropertyHelper.Register<MapBase, FrameworkElement>(nameof(MapLayer), null,
(map, oldValue, newValue) => map.MapLayerPropertyChanged(oldValue, newValue));
public static readonly DependencyProperty MapProjectionProperty =
DependencyPropertyHelper.Register<MapBase, MapProjection>(nameof(MapProjection), new WebMercatorProjection(),
(map, oldValue, newValue) => map.MapProjectionPropertyChanged(newValue));
@ -84,17 +74,6 @@ namespace MapControl
set => SetValue(AnimationDurationProperty, value);
}
/// <summary>
/// Gets or sets the base map layer, which is added as first element to the Children collection.
/// If the layer implements IMapLayer (like MapTileLayer or MapImageLayer), its (non-null) MapBackground
/// and MapForeground property values are used for the MapBase Background and Foreground properties.
/// </summary>
public FrameworkElement MapLayer
{
get => (FrameworkElement)GetValue(MapLayerProperty);
set => SetValue(MapLayerProperty, value);
}
/// <summary>
/// Gets or sets the MapProjection used by the map control.
/// </summary>
@ -440,49 +419,6 @@ namespace MapControl
internalPropertyChange = false;
}
private void MapLayerPropertyChanged(FrameworkElement oldLayer, FrameworkElement newLayer)
{
if (oldLayer != null)
{
if (Children.Count > 0 && Children[0] == oldLayer)
{
Children.RemoveAt(0);
}
if (oldLayer is IMapLayer mapLayer)
{
if (mapLayer.MapBackground != null)
{
ClearValue(BackgroundProperty);
}
if (mapLayer.MapForeground != null)
{
ClearValue(ForegroundProperty);
}
}
}
if (newLayer != null)
{
if (Children.Count == 0 || Children[0] != newLayer)
{
Children.Insert(0, newLayer);
}
if (newLayer is IMapLayer mapLayer)
{
if (mapLayer.MapBackground != null)
{
Background = mapLayer.MapBackground;
}
if (mapLayer.MapForeground != null)
{
Foreground = mapLayer.MapForeground;
}
}
}
}
private void MapProjectionPropertyChanged(MapProjection projection)
{
maxLatitude = 90d;