From 1d4c5a4b90b9d771f62aef6c8dfaa8fbb910a87b Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Thu, 9 Apr 2026 20:40:14 +0200 Subject: [PATCH] Changed IMapLayer interface --- MapControl/Shared/MapBase.MapLayer.cs | 3 +-- MapControl/Shared/MapImageLayer.cs | 9 +-------- MapControl/Shared/MapTileLayer.cs | 5 +---- MapControl/Shared/TilePyramidLayer.cs | 2 -- MapControl/Shared/WmsImageLayer.cs | 23 ++++++++++++++-------- MapControl/Shared/WmtsTileLayer.cs | 5 ----- MapUiTools/Shared/MapProjectionMenuItem.cs | 12 ++++++++--- MapUiTools/UWP/MapUiTools.UWP.csproj | 1 + 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/MapControl/Shared/MapBase.MapLayer.cs b/MapControl/Shared/MapBase.MapLayer.cs index 7a2da4fc..a94e46c5 100644 --- a/MapControl/Shared/MapBase.MapLayer.cs +++ b/MapControl/Shared/MapBase.MapLayer.cs @@ -23,7 +23,6 @@ namespace MapControl { Brush MapBackground { get; } Brush MapForeground { get; } - IReadOnlyCollection SupportedCrsIds { get; } } public partial class MapBase @@ -40,7 +39,7 @@ namespace MapControl /// Gets or sets the base map layer, which is added as first element to the Children collection. /// If the passed object is not a FrameworkElement, MapBase tries to locate a DataTemplate /// resource for the object's type and generate a FrameworkElement from that DataTemplate. - /// If the FrameworkElement implements IMapLayer (like e.g. MapTileLayer or MapImageLayer), + /// If the FrameworkElement implements IMapLayer (like e.g. TilePyramidLayer or MapImageLayer), /// its (non-null) MapBackground and MapForeground property values are used for the MapBase /// Background and Foreground. /// diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index a7edd1e6..3ec3ae49 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #if WPF @@ -127,11 +126,6 @@ namespace MapControl /// public double LoadingProgress => (double)GetValue(LoadingProgressProperty); - /// - /// Gets a collection of all CRSs supported by a MapImageLayer. - /// - public IReadOnlyCollection SupportedCrsIds { get; protected set; } - protected override void SetParentMap(MapBase map) { if (map != null) @@ -182,8 +176,7 @@ namespace MapControl ImageSource image = null; Rect? mapRect = null; - if (ParentMap != null && - (SupportedCrsIds == null || SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId))) + if (ParentMap != null) { var width = ParentMap.ActualWidth * RelativeImageSize; var height = ParentMap.ActualHeight * RelativeImageSize; diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 33b6101a..5a61fdd7 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; #if WPF using System.Windows; using System.Windows.Media; @@ -57,8 +56,6 @@ namespace MapControl this.SetRenderTransform(new MatrixTransform()); } - public override IReadOnlyCollection SupportedCrsIds { get; } = [WebMercatorProjection.DefaultCrsId]; - public TileMatrix TileMatrix { get; private set; } public ICollection Tiles { get; private set; } = []; @@ -149,7 +146,7 @@ namespace MapControl private void UpdateTileCollection(bool tileSourceChanged) { - if (TileSource == null || ParentMap == null || !SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId)) + if (TileSource == null || ParentMap?.MapProjection.CrsId != WebMercatorProjection.DefaultCrsId) { CancelLoadTiles(); Children.Clear(); diff --git a/MapControl/Shared/TilePyramidLayer.cs b/MapControl/Shared/TilePyramidLayer.cs index 8ca34fcf..82815383 100644 --- a/MapControl/Shared/TilePyramidLayer.cs +++ b/MapControl/Shared/TilePyramidLayer.cs @@ -171,8 +171,6 @@ namespace MapControl public bool IsBaseMapLayer => ParentMap != null && ParentMap.Children.Count > 0 && ParentMap.Children[0] == this; - public abstract IReadOnlyCollection SupportedCrsIds { get; } - protected void BeginLoadTiles(IEnumerable tiles, TileSource tileSource, string cacheName) { TileImageLoader.BeginLoadTiles(tiles, tileSource, cacheName, loadingProgress); diff --git a/MapControl/Shared/WmsImageLayer.cs b/MapControl/Shared/WmsImageLayer.cs index a3563eda..63ee854e 100644 --- a/MapControl/Shared/WmsImageLayer.cs +++ b/MapControl/Shared/WmsImageLayer.cs @@ -73,6 +73,11 @@ namespace MapControl /// public IReadOnlyCollection AvailableLayers { get; private set; } + /// + /// Gets a collection of all CRSs supported by a WMS. + /// + public IReadOnlyCollection SupportedCrsIds { get; private set; } + private bool HasLayer => RequestLayers != null || AvailableLayers?.Count > 0 || @@ -113,17 +118,17 @@ namespace MapControl var ns = capabilities.Name.Namespace; var capability = capabilities.Element(ns + "Capability"); - SupportedCrsIds = capability - .Descendants(ns + "Layer") - .Descendants(ns + "CRS") - .Select(e => e.Value) - .ToList(); - AvailableLayers = capability .Descendants(ns + "Layer") .Select(e => e.Element(ns + "Name")?.Value) .Where(n => !string.IsNullOrEmpty(n)) .ToList(); + + SupportedCrsIds = capability + .Descendants(ns + "Layer") + .Descendants(ns + "CRS") + .Select(e => e.Value) + .ToList(); } } @@ -161,7 +166,8 @@ namespace MapControl string response = null; if (ServiceUri != null && HasLayer && - ParentMap != null && ParentMap.InsideViewBounds(position)) + ParentMap != null && ParentMap.InsideViewBounds(position) && + (SupportedCrsIds == null || SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId))) { var uri = GetFeatureInfoRequestUri(position, format); @@ -185,7 +191,8 @@ namespace MapControl { ImageSource image = null; - if (ServiceUri != null && HasLayer) + if (ServiceUri != null && HasLayer && + (SupportedCrsIds == null || SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId))) { var xMin = -180d * MapProjection.Wgs84MeterPerDegree; var xMax = 180d * MapProjection.Wgs84MeterPerDegree; diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 7a2cc590..66763db2 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -79,11 +79,6 @@ namespace MapControl /// public Dictionary TileMatrixSets { get; } = []; - /// - /// Gets a collection of all CRSs supported by a WMTS. - /// - public override IReadOnlyCollection SupportedCrsIds => TileMatrixSets.Keys; - protected IEnumerable ChildLayers => Children.Cast(); protected override Size MeasureOverride(Size availableSize) diff --git a/MapUiTools/Shared/MapProjectionMenuItem.cs b/MapUiTools/Shared/MapProjectionMenuItem.cs index e2fef93a..6648cd9e 100644 --- a/MapUiTools/Shared/MapProjectionMenuItem.cs +++ b/MapUiTools/Shared/MapProjectionMenuItem.cs @@ -28,9 +28,15 @@ namespace MapControl.UiTools protected override bool GetIsEnabled(MapBase map) { - return map.MapLayer is not IMapLayer mapLayer - || mapLayer.SupportedCrsIds == null - || mapLayer.SupportedCrsIds.Contains(CrsId); + var supportedCrsIds = map.MapLayer switch + { + WmsImageLayer wmsImageLayer => wmsImageLayer.SupportedCrsIds, + WmtsTileLayer wmtsTileLayer => wmtsTileLayer.TileMatrixSets.Keys, + MapTileLayer => [WebMercatorProjection.DefaultCrsId], + _ => null + }; + + return supportedCrsIds == null || supportedCrsIds.Contains(CrsId); } protected override bool GetIsChecked(MapBase map) diff --git a/MapUiTools/UWP/MapUiTools.UWP.csproj b/MapUiTools/UWP/MapUiTools.UWP.csproj index d7774193..50a9bc26 100644 --- a/MapUiTools/UWP/MapUiTools.UWP.csproj +++ b/MapUiTools/UWP/MapUiTools.UWP.csproj @@ -6,6 +6,7 @@ UWP MapControl.UiTools XAML Map Control UI Tools Library for UWP + true true en-US