Skip to content

Commit 755d2f0

Browse files
committed
add backZoomOffset
1 parent eaf0f72 commit 755d2f0

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

src/layer/tile/TileLayer.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ const options = {
140140

141141
'decodeImageInWorker': false,
142142

143-
'tileLimitPerFrame': 0
143+
'tileLimitPerFrame': 0,
144+
145+
'backZoomOffset': 0
144146
};
145147

146148
const URL_PATTERN = /\{ *([\w_]+) *\}/g;
@@ -378,6 +380,7 @@ class TileLayer extends Layer {
378380
const offsets = {
379381
0: offset0
380382
};
383+
const preservedZoom = this.options['backZoomOffset'] + z;
381384
const extent = new PointExtent();
382385
const tiles = [];
383386
while (queue.length > 0) {
@@ -391,13 +394,19 @@ class TileLayer extends Layer {
391394
offsets[node.z + 1] = this._getTileOffset(node.z + 1);
392395
}
393396
this._splitNode(node, projectionView, queue, tiles, extent, maxZoom, offsets[node.z + 1], layer && layer.getRenderer(), glRes);
397+
if (preservedZoom < z && tiles[tiles.length - 1] !== node && preservedZoom === node.z) {
398+
// extent._combine(node.extent2d);
399+
tiles.push(node);
400+
}
394401
}
395402
return {
396403
tileGrids: [
397404
{
398405
extent,
399406
count: tiles.length,
400-
tiles
407+
tiles,
408+
offset: [0, 0],
409+
zoom: z
401410
}
402411
],
403412
count: tiles.length
@@ -432,33 +441,34 @@ class TileLayer extends Layer {
432441
const childIdy = (idy << 1) + dy;
433442

434443
// const tileId = this._getTileId(childIdx, childIdy, z);
444+
if (!node.children) {
445+
node.children = [];
446+
}
435447
let tileId = node.children[i];
436448
if (!tileId) {
437449
tileId = this._getTileId(childIdx, childIdy, z);
438450
node.children[i] = tileId;
439451
}
440452
const cached = renderer.isTileCachedOrLoading(tileId);
441453
let extent;
442-
if (!cached) {
443-
if (scaleY < 0) {
444-
const nwx = minx + dx * width;
445-
const nwy = maxy - dy * height;
446-
// extent2d 是 node.z 级别上的 extent
447-
extent = new PointExtent(nwx, nwy - height, nwx + width, nwy);
448-
449-
} else {
450-
const swx = minx + dx * width;
451-
const swy = miny + dy * height;
452-
extent = new PointExtent(swx, swy, swx + width, swy + height);
453-
}
454-
}
455454
let childNode = cached && cached.info;
456455
if (!childNode) {
457-
if (!this._infoCache) {
458-
this._infoCache = new LRUCache(this.options['maxCacheSize']);
456+
if (!this.tileInfoCache) {
457+
this.tileInfoCache = new LRUCache(this.options['maxCacheSize'] * 4);
459458
}
460-
childNode = this._infoCache.get(tileId);
459+
childNode = this.tileInfoCache.get(tileId);
461460
if (!childNode) {
461+
if (scaleY < 0) {
462+
const nwx = minx + dx * width;
463+
const nwy = maxy - dy * height;
464+
// extent2d 是 node.z 级别上的 extent
465+
extent = new PointExtent(nwx, nwy - height, nwx + width, nwy);
466+
467+
} else {
468+
const swx = minx + dx * width;
469+
const swy = miny + dy * height;
470+
extent = new PointExtent(swx, swy, swx + width, swy + height);
471+
}
462472
childNode = {
463473
x: childX,
464474
y: childY,
@@ -474,7 +484,7 @@ class TileLayer extends Layer {
474484
url: this.getTileUrl(childX, childY, z + this.options['zoomOffset']),
475485
offset
476486
};
477-
this._infoCache.add(tileId, childNode);
487+
this.tileInfoCache.add(tileId, childNode);
478488
}
479489
if (parentRenderer) {
480490
childNode['layer'] = this.getId();
@@ -489,6 +499,7 @@ class TileLayer extends Layer {
489499
} else if (visible === -1) {
490500
continue;
491501
} else if (visible === 0 && z !== maxZoom) {
502+
// 任意子瓦片的error低于maxError,则添加父级瓦片,不再遍历子瓦片
492503
tiles.push(node);
493504
gridExtent._combine(node.extent2d);
494505
return;
@@ -1054,6 +1065,8 @@ class TileLayer extends Layer {
10541065
});
10551066
}
10561067
return {
1068+
'offset': offset,
1069+
'zoom': tileZoom,
10571070
'extent': extent,
10581071
'tiles': tiles
10591072
};

src/renderer/layer/tilelayer/TileLayerCanvasRenderer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
181181
const tileGrid = tileGrids[i];
182182
const allTiles = tileGrid['tiles'];
183183

184-
const placeholder = this._generatePlaceHolder(allTiles[0].res);
184+
let placeholder;
185+
if (allTiles.length) {
186+
placeholder = this._generatePlaceHolder(allTiles[0].res);
187+
}
185188

186189
for (let j = 0, l = allTiles.length; j < l; j++) {
187190
const tile = allTiles[j],

0 commit comments

Comments
 (0)