Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cache size based on correct tile size rather than global map tile… #5459

Merged
merged 2 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ class SourceCache extends Evented {
* the map is more important.
*/
updateCacheSize(transform: Transform) {
const widthInTiles = Math.ceil(transform.width / transform.tileSize) + 1;
const heightInTiles = Math.ceil(transform.height / transform.tileSize) + 1;
const widthInTiles = Math.ceil(transform.width / this._source.tileSize) + 1;
const heightInTiles = Math.ceil(transform.height / this._source.tileSize) + 1;
const approxTilesInView = widthInTiles * heightInTiles;
const commonZoomRange = 5;

Expand All @@ -344,7 +344,6 @@ class SourceCache extends Evented {
if (!this._sourceLoaded || this._paused) { return; }

this.updateCacheSize(transform);

// Covered is a list of retained tiles who's areas are fully covered by other,
// better, retained tiles. They are not drawn separately.
this._coveredTiles = {};
Expand Down
34 changes: 34 additions & 0 deletions test/unit/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,3 +1372,37 @@ test('SourceCache reloads expiring tiles', (t) => {

t.end();
});

test('SourceCache sets max cache size correctly', (t) => {
t.test('sets cache size based on 512 tiles', (t) => {
const sourceCache = createSourceCache({
tileSize: 256
});

const tr = new Transform();
tr.width = 512;
tr.height = 512;
sourceCache.updateCacheSize(tr);

// Expect max size to be ((512 / tileSize + 1) ^ 2) * 5 => 3 * 3 * 5
t.equal(sourceCache._cache.max, 45);
t.end();
});

t.test('sets cache size based on 256 tiles', (t) => {
const sourceCache = createSourceCache({
tileSize: 512
});

const tr = new Transform();
tr.width = 512;
tr.height = 512;
sourceCache.updateCacheSize(tr);

// Expect max size to be ((512 / tileSize + 1) ^ 2) * 5 => 2 * 2 * 5
t.equal(sourceCache._cache.max, 20);
t.end();
});

t.end();
});