From 35df5e00e6ca7a62bf984760aeb3f1d24769381d Mon Sep 17 00:00:00 2001 From: David Manthey Date: Wed, 9 Feb 2022 12:58:51 -0500 Subject: [PATCH] bug: Tile layers with keepLower: false purged tiles on high zoom If a map allows zooming further than a tile set has layers and keepLower is set to false, the tiles would be purged. --- src/tileLayer.js | 9 +++++++-- tests/cases/tileLayer.js | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tileLayer.js b/src/tileLayer.js index 2fab6f775a..17b5822a40 100644 --- a/src/tileLayer.js +++ b/src/tileLayer.js @@ -676,7 +676,10 @@ var tileLayer = function (arg) { this._getTiles = function (maxLevel, bounds, sorted, onlyIfChanged) { var i, j, tiles = [], index, nTilesLevel, start, end, indexRange, source, center, changed = false, old, level, - minLevel = (m_this._options.keepLower ? m_this._options.minLevel : Math.max(maxLevel, m_this._options.minLevel)); + minLevel = ( + m_this._options.keepLower ? + m_this._options.minLevel : + Math.min(Math.max(maxLevel, m_this._options.minLevel), m_this._options.maxLevel)); if (maxLevel < minLevel) { maxLevel = minLevel; } @@ -1533,7 +1536,9 @@ var tileLayer = function (arg) { * semi-transparent layers. */ if ((doneLoading || m_this._isCovered(tile)) && zoom !== tile.index.level && - (zoom >= m_this._options.minLevel || tile.index.level !== m_this._options.minLevel)) { + (zoom >= m_this._options.minLevel || tile.index.level !== m_this._options.minLevel) && + (zoom < m_this._options.maxLevel || tile.index.level !== m_this._options.maxLevel) + ) { return true; } } diff --git a/tests/cases/tileLayer.js b/tests/cases/tileLayer.js index e1dc9c5b1e..5a6740e101 100644 --- a/tests/cases/tileLayer.js +++ b/tests/cases/tileLayer.js @@ -1257,6 +1257,13 @@ describe('geo.tileLayer', function () { expect(l._canPurge({index: {level: 2}}, {}, 1, true)).toBe(true); expect(l._canPurge({index: {level: 2}}, {}, 1, false)).toBe(false); }); + it('past max zoom', function () { + var l = geo.tileLayer({map: map({max: 3}), keepLower: true}); + l._outOfBounds = function () { return false; }; + expect(l._canPurge({index: {level: 2}}, {}, 3)).toBe(false); + expect(l._canPurge({index: {level: 2}}, {}, 2)).toBe(false); + expect(l._canPurge({index: {level: 2}}, {}, 1)).toBe(true); + }); }); describe('_outOfBounds', function () {