Tile layer background levels

This commit is contained in:
ClemensFischer 2025-11-27 20:06:48 +01:00
parent 05750d669c
commit ec99fc0cf7
2 changed files with 36 additions and 32 deletions

View file

@ -190,9 +190,13 @@ namespace MapControl
if (maxZoomLevel >= MinZoomLevel) if (maxZoomLevel >= MinZoomLevel)
{ {
var minZoomLevel = IsBaseMapLayer var minZoomLevel = maxZoomLevel;
? Math.Max(TileMatrix.ZoomLevel - MaxBackgroundLevels, MinZoomLevel)
: maxZoomLevel; if (IsBaseMapLayer)
{
var bgLevels = Math.Max(MaxBackgroundLevels, 0);
minZoomLevel = Math.Max(TileMatrix.ZoomLevel - bgLevels, MinZoomLevel);
}
for (var zoomLevel = minZoomLevel; zoomLevel <= maxZoomLevel; zoomLevel++) for (var zoomLevel = minZoomLevel; zoomLevel <= maxZoomLevel; zoomLevel++)
{ {

View file

@ -143,37 +143,36 @@ namespace MapControl
private bool UpdateChildLayers(WmtsTileMatrixSet tileMatrixSet) private bool UpdateChildLayers(WmtsTileMatrixSet tileMatrixSet)
{ {
// Multiply scale by 1.001 to avoid rounding issues. // Multiply scale by 1.001 to avoid floating point precision issues
// and get all WmtsTileMatrixes with Scale <= maxScale.
// //
var maxScale = 1.001 * ParentMap.ViewTransform.Scale; var maxScale = 1.001 * ParentMap.ViewTransform.Scale;
var tileMatrixes = tileMatrixSet.TileMatrixes.Where(matrix => matrix.Scale <= maxScale).ToList();
var childLayers = ChildLayers.Where(layer => tileMatrixes.Contains(layer.WmtsTileMatrix)).ToList();
var tilesChanged = false;
// Show all WmtsTileMatrix layers with Scale <= maxScale, at least the first layer. Children.Clear();
//
var currentMatrixes = tileMatrixSet.TileMatrixes if (tileMatrixes.Count > 0)
.Where((matrix, i) => i == 0 || matrix.Scale <= maxScale) {
.ToList(); var maxLayers = Math.Max(MaxBackgroundLevels, 0) + 1;
if (!IsBaseMapLayer) if (!IsBaseMapLayer)
{ {
// Show only the last layer. // Show only the last layer.
// //
currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - 1).ToList(); tileMatrixes = tileMatrixes.GetRange(tileMatrixes.Count - 1, 1);
} }
else if (currentMatrixes.Count > MaxBackgroundLevels + 1) else if (tileMatrixes.Count > maxLayers)
{ {
// Show not more than MaxBackgroundLevels + 1 layers. // Show not more than MaxBackgroundLevels + 1 layers.
// //
currentMatrixes = currentMatrixes.Skip(currentMatrixes.Count - MaxBackgroundLevels - 1).ToList(); tileMatrixes = tileMatrixes.GetRange(tileMatrixes.Count - maxLayers, maxLayers);
} }
var currentLayers = ChildLayers.Where(layer => currentMatrixes.Contains(layer.WmtsTileMatrix)).ToList(); foreach (var tileMatrix in tileMatrixes)
var tilesChanged = false;
Children.Clear();
foreach (var tileMatrix in currentMatrixes)
{ {
var layer = currentLayers.FirstOrDefault(layer => layer.WmtsTileMatrix == tileMatrix) ?? var layer = childLayers.FirstOrDefault(layer => layer.WmtsTileMatrix == tileMatrix) ??
new WmtsTileMatrixLayer(tileMatrix, tileMatrixSet.TileMatrixes.IndexOf(tileMatrix)); new WmtsTileMatrixLayer(tileMatrix, tileMatrixSet.TileMatrixes.IndexOf(tileMatrix));
if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.ActualWidth, ParentMap.ActualHeight)) if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.ActualWidth, ParentMap.ActualHeight))
@ -185,6 +184,7 @@ namespace MapControl
Children.Add(layer); Children.Add(layer);
} }
}
return tilesChanged; return tilesChanged;
} }