Compare commits

..

2 commits

Author SHA1 Message Date
ClemensFischer 0f3635b97a Comments 2025-11-27 23:18:57 +01:00
ClemensFischer ec99fc0cf7 Tile layer background levels 2025-11-27 20:06:48 +01:00
3 changed files with 39 additions and 34 deletions

View file

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

View file

@ -143,37 +143,39 @@ namespace MapControl
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 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.
//
var currentMatrixes = tileMatrixSet.TileMatrixes
.Where((matrix, i) => i == 0 || matrix.Scale <= maxScale)
.ToList();
Children.Clear();
if (tileMatrixes.Count > 0)
{
var maxLayers = Math.Max(MaxBackgroundLevels, 0) + 1;
if (!IsBaseMapLayer)
{
// 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.
//
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();
var tilesChanged = false;
Children.Clear();
foreach (var tileMatrix in currentMatrixes)
foreach (var tileMatrix in tileMatrixes)
{
var layer = currentLayers.FirstOrDefault(layer => layer.WmtsTileMatrix == tileMatrix) ??
// Reuse existing WmtsTileMatrixLayer or create a new one with the
// index of tileMatrix in tileMatrixSet.TileMatrixes as zoom level.
//
var layer = childLayers.FirstOrDefault(layer => layer.WmtsTileMatrix == tileMatrix) ??
new WmtsTileMatrixLayer(tileMatrix, tileMatrixSet.TileMatrixes.IndexOf(tileMatrix));
if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.ActualWidth, ParentMap.ActualHeight))
@ -185,6 +187,7 @@ namespace MapControl
Children.Add(layer);
}
}
return tilesChanged;
}

View file

@ -22,8 +22,6 @@ namespace MapControl
{
public class WmtsTileMatrixLayer : Panel
{
// zoomLevel is index of tileMatrix in a WmtsTileMatrixSet.TileMatrixes list.
//
public WmtsTileMatrixLayer(WmtsTileMatrix wmtsTileMatrix, int zoomLevel)
{
this.SetRenderTransform(new MatrixTransform());