From 73ffda10db762a8337b9a1ea994fdf2d4ad4f53f Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 16 Nov 2018 12:19:29 +0100 Subject: [PATCH] Smarter interim tile creation --- src/ol/VectorImageTile.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ol/VectorImageTile.js b/src/ol/VectorImageTile.js index eaa36142c9..a8531a7dbe 100644 --- a/src/ol/VectorImageTile.js +++ b/src/ol/VectorImageTile.js @@ -6,7 +6,7 @@ import Tile from './Tile.js'; import TileState from './TileState.js'; import {createCanvasContext2D} from './dom.js'; import {listen, unlistenByKey} from './events.js'; -import {getHeight, getIntersection, getWidth} from './extent.js'; +import {containsExtent, getHeight, getIntersection, getWidth} from './extent.js'; import EventType from './events/EventType.js'; import {loadFeaturesXhr} from './featureloader.js'; import {VOID} from './functions.js'; @@ -103,6 +103,8 @@ class VectorImageTile extends Tile { */ this.sourceTileListenerKeys_ = []; + this.sourceTilesLoaded = false; + /** * Use only source tiles that are loaded already * @type {boolean} @@ -148,16 +150,24 @@ class VectorImageTile extends Tile { this.finishLoading_(); } - if (zoom <= tileCoord[0] && this.state != TileState.LOADED) { - while (zoom > tileGrid.getMinZoom()) { + 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]; + } + } + } + if (bestZoom !== -1) { const tile = new VectorImageTile(tileCoord, state, sourceRevision, format, tileLoadFunction, urlTileCoord, tileUrlFunction, sourceTileGrid, tileGrid, sourceTiles, pixelRatio, projection, - tileClass, VOID, --zoom); - if (tile.state == TileState.LOADED) { - this.interimTile = tile; - break; - } + tileClass, VOID, bestZoom); + this.interimTile = tile; } } } @@ -168,6 +178,7 @@ class VectorImageTile extends Tile { * @inheritDoc */ disposeInternal() { + this.getInterimTile = super.getInterimTile; this.state = TileState.ABORT; this.changed(); if (this.interimTile) { @@ -312,6 +323,7 @@ class VectorImageTile extends Tile { if (loaded == this.tileKeys.length) { this.loadListenerKeys_.forEach(unlistenByKey); this.loadListenerKeys_.length = 0; + this.sourceTilesLoaded = true; this.setState(TileState.LOADED); } else { this.setState(empty == this.tileKeys.length ? TileState.EMPTY : TileState.ERROR);