Skip to content

Commit efcc5e4

Browse files
committed
set caches public in tilelayer renderer and some updates
1 parent 07705ab commit efcc5e4

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

src/renderer/layer/tilelayer/TileLayerCanvasRenderer.js

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
2727
*/
2828
constructor(layer) {
2929
super(layer);
30-
this._tileRended = {};
31-
this._tileLoading = {};
32-
this._tileCache = new LruCache(layer.options['maxCacheSize'], this.deleteTile.bind(this));
30+
this.tilesInView = {};
31+
this.tilesLoading = {};
32+
this.tileCache = new LruCache(layer.options['maxCacheSize'], this.deleteTile.bind(this));
3333
}
3434

3535
prepareRender() {
@@ -89,8 +89,8 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
8989
loading = true;
9090
}
9191
this.drawTile(cached.info, cached.image);
92-
if (cached !== this._tileCache.get(tileId)) {
93-
this._tileCache.add(tileId, cached);
92+
if (cached !== this.tileCache.get(tileId)) {
93+
this.tileCache.add(tileId, cached);
9494
}
9595
} else {
9696
loading = true;
@@ -170,14 +170,14 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
170170

171171
clear() {
172172
this._clearCaches();
173-
this._tileRended = {};
174-
this._tileLoading = {};
175-
this._tileCache.reset();
173+
this.tilesInView = {};
174+
this.tilesLoading = {};
175+
this.tileCache.reset();
176176
super.clear();
177177
}
178178

179179
_isLoadingTile(tileId) {
180-
return !!this._tileLoading[tileId];
180+
return !!this.tilesLoading[tileId];
181181
}
182182

183183
clipCanvas(context) {
@@ -213,10 +213,10 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
213213
if (tileQueue.hasOwnProperty(p)) {
214214
const tile = tileQueue[p];
215215
const tileImage = this.loadTile(tile);
216-
if (!tileImage.loadTime) {
216+
if (tileImage.loadTime === undefined) {
217217
// tile image's loading may not be async
218218
tileImage.current = true;
219-
this._tileLoading[tile['id']] = {
219+
this.tilesLoading[tile['id']] = {
220220
image : tileImage,
221221
current : true,
222222
info : tile
@@ -260,12 +260,12 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
260260
return;
261261
}
262262
const id = tileInfo['id'];
263-
if (!this._tileRended) {
263+
if (!this.tilesInView) {
264264
// removed
265265
return;
266266
}
267267
tileImage.loadTime = now();
268-
delete this._tileLoading[id];
268+
delete this.tilesLoading[id];
269269
this._addTileToCache(tileInfo, tileImage);
270270
this.setToRedraw();
271271
/**
@@ -289,7 +289,7 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
289289
this.cancelTileLoading(tileImage);
290290
}
291291
tileImage.loadTime = 0;
292-
delete this._tileLoading[tileInfo['id']];
292+
delete this.tilesLoading[tileInfo['id']];
293293
this._addTileToCache(tileInfo, tileImage);
294294
this.setToRedraw();
295295
/**
@@ -369,25 +369,27 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
369369
}
370370

371371
_getCachedTile(tileId) {
372-
let cached = this._tileRended[tileId];
373-
if (this._tileRended[tileId]) {
374-
this._tileRended[tileId].current = true;
372+
const tilesInView = this.tilesInView;
373+
let cached = tilesInView[tileId];
374+
if (tilesInView[tileId]) {
375+
tilesInView[tileId].current = true;
375376
}
376-
if (this._tileLoading && this._tileLoading[tileId]) {
377-
this._tileLoading[tileId].current = true;
377+
const tilesLoading = this.tilesLoading;
378+
if (tilesLoading && tilesLoading[tileId]) {
379+
tilesLoading[tileId].current = true;
378380
}
379381
if (!cached) {
380-
cached = this._tileCache.get(tileId);
382+
cached = this.tileCache.get(tileId);
381383
if (cached) {
382384
cached.current = true;
383-
this._tileRended[tileId] = cached;
385+
tilesInView[tileId] = cached;
384386
}
385387
}
386388
return cached;
387389
}
388390

389391
_addTileToCache(tileInfo, tileImage) {
390-
this._tileRended[tileInfo.id] = {
392+
this.tilesInView[tileInfo.id] = {
391393
image : tileImage,
392394
current : true,
393395
info : tileInfo
@@ -402,51 +404,53 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
402404
}
403405

404406
onRemove() {
405-
this._tileCache.reset();
407+
this.tileCache.reset();
406408
this._clearCaches();
407409
}
408410

409411
_clearCaches() {
410-
delete this._tileRended;
412+
delete this.tilesInView;
411413
delete this._tileZoom;
412-
delete this._tileLoading;
414+
delete this.tilesLoading;
413415
delete this._backCanvas;
414416
}
415417

416418
_markTiles() {
417419
let a = 0, b = 0;
418-
if (this._tileLoading) {
419-
for (const p in this._tileLoading) {
420-
this._tileLoading[p].current = false;
420+
if (this.tilesLoading) {
421+
for (const p in this.tilesLoading) {
422+
this.tilesLoading[p].current = false;
421423
a++;
422424
}
423425
}
424-
if (this._tileRended) {
425-
for (const p in this._tileRended) {
426-
this._tileRended[p].current = false;
426+
if (this.tilesInView) {
427+
for (const p in this.tilesInView) {
428+
this.tilesInView[p].current = false;
427429
b++;
428430
}
429431
}
430432
return [a, b];
431433
}
432434

433435
_retireTiles() {
434-
for (const i in this._tileLoading) {
435-
const tile = this._tileLoading[i];
436+
for (const i in this.tilesLoading) {
437+
const tile = this.tilesLoading[i];
436438
if (!tile.current) {
437439
// abort loading tiles
438440
if (tile.image) {
439441
this.cancelTileLoading(tile.image);
440442
}
441443
this.deleteTile(tile);
442-
delete this._tileLoading[i];
444+
delete this.tilesLoading[i];
443445
}
444446
}
445-
for (const i in this._tileRended) {
446-
const tile = this._tileRended[i];
447-
if (!tile.current && !this._tileCache.has(i)) {
448-
this.deleteTile(tile);
449-
delete this._tileRended[i];
447+
for (const i in this.tilesInView) {
448+
const tile = this.tilesInView[i];
449+
if (!tile.current) {
450+
delete this.tilesInView[i];
451+
if (!this.tileCache.has(i)) {
452+
this.deleteTile(tile);
453+
}
450454
}
451455
}
452456
}

src/renderer/layer/tilelayer/TileLayerGLRenderer.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,17 @@ class TileLayerGLRenderer extends ImageGLRenderable(TileLayerCanvasRenderer) {
121121
const parentTile = this.background[p];
122122
if (this.layer._isTileInExtent(parentTile.info, extent)) {
123123
parentTile.current = true;
124-
this.drawTile(parentTile.info, parentTile.image);
124+
this.drawBackgroundTile(parentTile.info, parentTile.image);
125125
}
126126
}
127127
}
128128
}
129129
}
130130

131+
drawBackgroundTile(info, image) {
132+
this.drawTile(info, image);
133+
}
134+
131135
saveBackground() {
132136
if (this._gl && !this._gl()) {
133137
super.saveBackground();
@@ -138,11 +142,11 @@ class TileLayerGLRenderer extends ImageGLRenderable(TileLayerCanvasRenderer) {
138142
return;
139143
}
140144
this.background = {};
141-
const cache = this._tileRended;
145+
const cache = this.tilesInView;
142146
for (const p in cache) {
143147
const tile = cache[p];
144148
if (hasOwn(cache, p) && tile && tile.current) {
145-
tile.image.loadTime = 0;
149+
// tile.image.loadTime = 0;
146150
this.background[p] = tile;
147151
}
148152
}

0 commit comments

Comments
 (0)