Move interim tile related methods to ol.Tile

This commit is contained in:
Andreas Hocevar
2016-09-02 14:14:50 +02:00
committed by Thomas Moelhave
parent 69fc9edb4d
commit ed17cbc6f0
3 changed files with 57 additions and 70 deletions

View File

@@ -152,66 +152,3 @@ ol.ImageTile.prototype.unlistenImage_ = function() {
this.imageListenerKeys_.forEach(ol.events.unlistenByKey);
this.imageListenerKeys_ = null;
};
/**
* Get the interim tile most suitable for rendering using the chain of interim tiles.
* This corresponds to the most recent tile that has been loaded, if no such
* tile exists, the original tile is returned.
* @return {!ol.Tile} Best tile for rendering.
*/
ol.ImageTile.prototype.getInterimTile = function() {
if (!this.interimTile) {
//empty chain
return this;
}
var tile = this.interimTile;
//find the first loaded tile and return it. Since the chain is sorted in decreasing
//order of creation time, there is no need to search the remaineder of the list (all those
//tiles correspond to older requests and will be cleaned up by refreshInterimChain)
do {
if (tile.getState() == ol.Tile.State.LOADED) {
return tile;
}
tile = tile.interimTile;
} while (tile);
//we can not find a better tile
return this;
};
/**
* Goes through the chain of interim tiles starting and discards
* sections of the chain that are no longer relevant.
* @return {void}
* @private
*/
ol.ImageTile.prototype.refreshInterimChain = function() {
if (!this.interimTile) {
return;
}
var tile = this.interimTile;
var prev = this;
do {
if (tile.getState() == ol.Tile.State.LOADED) {
//we have a loaded tile, we can discard the rest of the list
//we would could abort any LOADING tile request
//older than this tile (i.e. any LOADING tile following this entry in the chain)
tile.interimTile = null;
break;
} else if (tile.getState() == ol.Tile.State.LOADING) {
//keep this LOADING tile any loaded tiles later in the chain are
//older than this tile, so we're still interested in the request
prev = tile;
} else if (tile.getState() == ol.Tile.State.IDLE) {
//the head of the list is the most current tile, we don't need
//to start any other requests for this chain
prev.interimTile = tile.interimTile;
} else {
prev = tile;
}
tile = prev.interimTile;
} while (tile);
};

View File

@@ -296,12 +296,12 @@ ol.source.TileImage.prototype.getTileInternal = function(z, x, y, pixelRatio, pr
tile = this.createTile_(z, x, y, pixelRatio, projection, key);
this.tileCache.set(tileCoordKey, tile);
} else {
tile = /** @type {!ol.Tile} */ (this.tileCache.get(tileCoordKey));
tile = this.tileCache.get(tileCoordKey);
if (tile.key != key) {
// The source's params changed. If the tile has an interim tile and if we
// can use it then we use it. Otherwise we create a new tile. In both
// cases we attempt to assign an interim tile to the new tile.
var /** @type {ol.Tile} */ interimTile = tile;
var interimTile = tile;
tile = this.createTile_(z, x, y, pixelRatio, projection, key);
//make the new tile the head of the list,

View File

@@ -73,17 +73,67 @@ ol.Tile.prototype.getKey = function() {
};
/**
* Get the interim tile if it exists, otherwise returns the tile itself.
* @return {!ol.Tile} The interim tile, or the tile itself
*
* Get the interim tile most suitable for rendering using the chain of interim
* tiles. This corresponds to the most recent tile that has been loaded, if no
* such tile exists, the original tile is returned.
* @return {!ol.Tile} Best tile for rendering.
*/
ol.Tile.prototype.getInterimTile = function() {
if (this.interimTile) {
return this.interimTile;
if (!this.interimTile) {
//empty chain
return this;
}
var tile = this.interimTile;
// find the first loaded tile and return it. Since the chain is sorted in
// decreasing order of creation time, there is no need to search the remainder
// of the list (all those tiles correspond to older requests and will be
// cleaned up by refreshInterimChain)
do {
if (tile.getState() == ol.Tile.State.LOADED) {
return tile;
}
tile = tile.interimTile;
} while (tile);
// we can not find a better tile
return this;
};
/**
* Goes through the chain of interim tiles and discards sections of the chain
* that are no longer relevant.
*/
ol.Tile.prototype.refreshInterimChain = function() {
if (!this.interimTile) {
return;
}
var tile = this.interimTile;
var prev = this;
do {
if (tile.getState() == ol.Tile.State.LOADED) {
//we have a loaded tile, we can discard the rest of the list
//we would could abort any LOADING tile request
//older than this tile (i.e. any LOADING tile following this entry in the chain)
tile.interimTile = null;
break;
} else if (tile.getState() == ol.Tile.State.LOADING) {
//keep this LOADING tile any loaded tiles later in the chain are
//older than this tile, so we're still interested in the request
prev = tile;
} else if (tile.getState() == ol.Tile.State.IDLE) {
//the head of the list is the most current tile, we don't need
//to start any other requests for this chain
prev.interimTile = tile.interimTile;
} else {
prev = tile;
}
tile = prev.interimTile;
} while (tile);
};
/**
* Get the tile coordinate for this tile.
* @return {ol.TileCoord} The tile coordinate.