From c17092cd38c94f9f9a7242798e19d4ead3c047ac Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 11 Nov 2021 22:27:57 +0100 Subject: [PATCH] Add IsBaseMapLayer property --- MapControl/Shared/MapTileLayer.cs | 2 +- MapControl/Shared/MapTileLayerBase.cs | 9 +++++++-- MapControl/Shared/WmtsTileLayer.cs | 6 +++--- SampleApps/ProjectionDemo/ProjectionDemo.csproj | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 4b77e5ad..9849df10 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -211,7 +211,7 @@ namespace MapControl } else { - var minZoomLevel = LoadBackgroundTiles + var minZoomLevel = IsBaseMapLayer ? Math.Max(TileMatrix.ZoomLevel - MaxBackgroundLevels, MinZoomLevel) : maxZoomLevel; diff --git a/MapControl/Shared/MapTileLayerBase.cs b/MapControl/Shared/MapTileLayerBase.cs index cf3f96a1..0ec2c284 100644 --- a/MapControl/Shared/MapTileLayerBase.cs +++ b/MapControl/Shared/MapTileLayerBase.cs @@ -176,9 +176,14 @@ namespace MapControl } } - protected bool LoadBackgroundTiles + protected bool IsBaseMapLayer { - get { return this == parentMap?.MapLayer; } + get + { + return parentMap != null + && parentMap.Children.Count > 0 + && parentMap.Children[0] == this; + } } private async void OnViewportChanged(object sender, ViewportChangedEventArgs e) diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index b5718fad..d10520ff 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -120,15 +120,15 @@ namespace MapControl var layersChanged = false; var maxScale = 1.001 * ParentMap.ViewTransform.Scale; // avoid rounding issues - // show all TileMatrix layers with Scale <= maxScale, at least the first layer + // show all WmtsTileMatrix layers with Scale <= maxScale, at least the first layer // var currentMatrixes = tileMatrixSet.TileMatrixes .Where((matrix, i) => i == 0 || matrix.Scale <= maxScale) .ToList(); - if (!LoadBackgroundTiles) + if (!IsBaseMapLayer) // show only the last layer { - currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - 1).ToList(); // last element only + currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - 1).ToList(); } else if (currentMatrixes.Count > MaxBackgroundLevels + 1) { diff --git a/SampleApps/ProjectionDemo/ProjectionDemo.csproj b/SampleApps/ProjectionDemo/ProjectionDemo.csproj index b501a207..2472a479 100644 --- a/SampleApps/ProjectionDemo/ProjectionDemo.csproj +++ b/SampleApps/ProjectionDemo/ProjectionDemo.csproj @@ -2,7 +2,7 @@ WinExe - net5.0-windows + net6.0-windows true 6.1.0 Clemens Fischer