Lazily create interim tiles (fixes most tests)

This commit is contained in:
ahocevar
2018-11-16 15:01:00 +01:00
parent d6add33df0
commit edbe2316ef
2 changed files with 31 additions and 23 deletions

View File

@@ -103,8 +103,6 @@ class VectorImageTile extends Tile {
*/
this.sourceTileListenerKeys_ = [];
this.sourceTilesLoaded = false;
/**
* Use only source tiles that are loaded already
* @type {boolean}
@@ -150,35 +148,44 @@ class VectorImageTile extends Tile {
this.finishLoading_();
}
if (!this.sourceTilesLoaded && !useLoadedOnly) {
let bestZoom = -1;
for (const key in sourceTiles) {
const sourceTile = sourceTiles[key];
if (sourceTile.getState() === TileState.LOADED) {
const sourceTileCoord = sourceTile.tileCoord;
const sourceTileExtent = sourceTileGrid.getTileCoordExtent(sourceTileCoord);
if (containsExtent(sourceTileExtent, extent) && sourceTileCoord[0] > bestZoom) {
bestZoom = sourceTileCoord[0];
this.createInterimTile_ = function() {
if (this.getState() !== TileState.LOADED && !useLoadedOnly) {
let bestZoom = -1;
for (const key in sourceTiles) {
const sourceTile = sourceTiles[key];
if (sourceTile.getState() === TileState.LOADED) {
const sourceTileCoord = sourceTile.tileCoord;
const sourceTileExtent = sourceTileGrid.getTileCoordExtent(sourceTileCoord);
if (containsExtent(sourceTileExtent, extent) && sourceTileCoord[0] > bestZoom) {
bestZoom = sourceTileCoord[0];
}
}
}
}
if (bestZoom !== -1) {
const tile = new VectorImageTile(tileCoord, state, sourceRevision,
format, tileLoadFunction, urlTileCoord, tileUrlFunction,
sourceTileGrid, tileGrid, sourceTiles, pixelRatio, projection,
tileClass, VOID, bestZoom);
this.interimTile = tile;
}
if (bestZoom !== -1) {
const tile = new VectorImageTile(tileCoord, state, sourceRevision,
format, tileLoadFunction, urlTileCoord, tileUrlFunction,
sourceTileGrid, tileGrid, sourceTiles, pixelRatio, projection,
tileClass, VOID, bestZoom);
this.interimTile = tile;
}
}
}
}
}
getInterimTile() {
if (!this.interimTile) {
this.createInterimTile_();
}
return super.getInterimTile();
}
/**
* @inheritDoc
*/
disposeInternal() {
this.getInterimTile = super.getInterimTile;
delete this.createInterimTile_;
this.state = TileState.ABORT;
this.changed();
if (this.interimTile) {

View File

@@ -75,6 +75,7 @@ describe('ol.renderer.canvas.VectorTileLayer', function() {
tileGrid: createXYZ()
});
source.getTile = function() {
arguments[1] = TileState.LOADED;
const tile = VectorTileSource.prototype.getTile.apply(source, arguments);
tile.setState(TileState.LOADED);
return tile;
@@ -106,7 +107,7 @@ describe('ol.renderer.canvas.VectorTileLayer', function() {
map.removeLayer(layer);
map.addLayer(testLayer);
const spy = sinon.spy(CanvasVectorTileLayerRenderer.prototype,
'getTransform');
'getRenderTransform');
map.renderSync();
expect(spy.callCount).to.be(0);
spy.restore();
@@ -114,7 +115,7 @@ describe('ol.renderer.canvas.VectorTileLayer', function() {
it('renders both replays and images for hybrid rendering', function() {
const spy1 = sinon.spy(CanvasVectorTileLayerRenderer.prototype,
'getTransform');
'getRenderTransform');
const spy2 = sinon.spy(CanvasVectorTileLayerRenderer.prototype,
'renderTileImage_');
map.renderSync();
@@ -129,7 +130,7 @@ describe('ol.renderer.canvas.VectorTileLayer', function() {
renderer: function() {}
}));
const spy = sinon.spy(CanvasVectorTileLayerRenderer.prototype,
'getTransform');
'getRenderTransform');
map.renderSync();
expect(spy.callCount).to.be(1);
spy.restore();