Skip to content

Commit

Permalink
bug: Tile layers with keepLower: false purged tiles on high zoom
Browse files Browse the repository at this point in the history
If a map allows zooming further than a tile set has layers and keepLower
is set to false, the tiles would be purged.
  • Loading branch information
manthey committed Feb 9, 2022
1 parent ab41131 commit 35df5e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 35df5e0

Please sign in to comment.