mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Compare commits
2 commits
05750d669c
...
0f3635b97a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f3635b97a | ||
|
|
ec99fc0cf7 |
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in a new issue