add documentation; rename parameters for clarity

This commit is contained in:
Tom 2023-12-21 15:10:23 -05:00
parent 55882b9215
commit 1588f6b715
2 changed files with 21 additions and 17 deletions

View File

@ -1040,10 +1040,14 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
* @returns {Array} Array of Tiles that make up the current view * @returns {Array} Array of Tiles that make up the current view
*/ */
getTilesToDraw: function(){ getTilesToDraw: function(){
// start with all the tiles added to this._tilesToDraw during the most recent
// call to this.update. Then update them so the blending and coverage properties
// are updated based on the current time
let tileArray = this._tilesToDraw.flat(); let tileArray = this._tilesToDraw.flat();
// update all tiles (so blending can happen right at the time of drawing)
// update all tiles, which can change the coverage provided
this._updateTilesInViewport(tileArray); this._updateTilesInViewport(tileArray);
// _tilesToDraw might have been updated by the update; refresh it // _tilesToDraw might have been updated by the update; refresh it
tileArray = this._tilesToDraw.flat(); tileArray = this._tilesToDraw.flat();
@ -1362,7 +1366,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
); );
// Update the level and keep track of 'best' tiles to load // Update the level and keep track of 'best' tiles to load
// the bestTiles
var result = this._updateLevel( var result = this._updateLevel(
haveDrawn, haveDrawn,
drawLevel, drawLevel,
@ -1374,8 +1378,8 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
bestTiles bestTiles
); );
bestTiles = result.best; bestTiles = result.bestTiles;
var tiles = result.tiles.filter(tile => tile.loaded); var tiles = result.updatedTiles.filter(tile => tile.loaded);
var makeTileInfoObject = (function(level, levelOpacity, currentTime){ var makeTileInfoObject = (function(level, levelOpacity, currentTime){
return function(tile){ return function(tile){
return { return {
@ -1451,7 +1455,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
} }
} }
// Update each tile in the _lastDrawn list. As the tiles are updated, // Update each tile in the list of tiles. As the tiles are updated,
// the coverage provided is also updated. If a level provides coverage // the coverage provided is also updated. If a level provides coverage
// as part of this process, discard tiles from lower levels // as part of this process, discard tiles from lower levels
let level = 0; let level = 0;
@ -1529,7 +1533,8 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
* @param {Number} levelVisibility * @param {Number} levelVisibility
* @param {OpenSeadragon.Rect} drawArea * @param {OpenSeadragon.Rect} drawArea
* @param {Number} currentTime * @param {Number} currentTime
* @param {Object} result Dictionary {best: OpenSeadragon.Tile - the current "best" tiles to draw, tiles: Array(OpenSeadragon.Tile) - the updated tiles}. * @param {OpenSeadragon.Tile[]} best Array of the current best tiles
* @returns {Object} Dictionary {bestTiles: OpenSeadragon.Tile - the current "best" tiles to draw, updatedTiles: OpenSeadragon.Tile) - the updated tiles}.
*/ */
_updateLevel: function(haveDrawn, drawLevel, level, levelOpacity, _updateLevel: function(haveDrawn, drawLevel, level, levelOpacity,
levelVisibility, drawArea, currentTime, best) { levelVisibility, drawArea, currentTime, best) {
@ -1624,15 +1629,15 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
currentTime, currentTime,
best best
); );
best = result.best; best = result.bestTiles;
tiles[tileIndex] = result.tile; tiles[tileIndex] = result.tile;
tileIndex += 1; tileIndex += 1;
} }
} }
return { return {
best: best, bestTiles: best,
tiles: tiles updatedTiles: tiles
}; };
}, },
@ -1702,6 +1707,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
* @param {Number} numberOfTiles * @param {Number} numberOfTiles
* @param {Number} currentTime * @param {Number} currentTime
* @param {OpenSeadragon.Tile} best - The current "best" tile to draw. * @param {OpenSeadragon.Tile} best - The current "best" tile to draw.
* @returns {Object} Dictionary {bestTiles: OpenSeadragon.Tile[] - the current best tiles, tile: OpenSeadragon.Tile the current tile}
*/ */
_updateTile: function( haveDrawn, drawLevel, x, y, level, _updateTile: function( haveDrawn, drawLevel, x, y, level,
levelVisibility, viewportCenter, numberOfTiles, currentTime, best){ levelVisibility, viewportCenter, numberOfTiles, currentTime, best){
@ -1739,7 +1745,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
if ( !tile.exists ) { if ( !tile.exists ) {
return { return {
best: best, bestTiles: best,
tile: tile tile: tile
}; };
} }
@ -1756,7 +1762,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
if ( !drawTile ) { if ( !drawTile ) {
return { return {
best: best, bestTiles: best,
tile: tile tile: tile
}; };
} }
@ -1788,7 +1794,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
} }
return { return {
best: best, bestTiles: best,
tile: tile tile: tile
}; };
}, },

View File

@ -368,10 +368,8 @@ $.TileSource.prototype = {
getTileAtPoint: function(level, point) { getTileAtPoint: function(level, point) {
var validPoint = point.x >= 0 && point.x <= 1 && var validPoint = point.x >= 0 && point.x <= 1 &&
point.y >= 0 && point.y <= 1 / this.aspectRatio; point.y >= 0 && point.y <= 1 / this.aspectRatio;
// $.console.assert(validPoint, "[TileSource.getTileAtPoint] must be called with a valid point."); $.console.assert(validPoint, "[TileSource.getTileAtPoint] must be called with a valid point.");
if(!validPoint){
$.console.warn("[TileSource.getTileAtPoint] called with an invalid point.");
}
var widthScaled = this.dimensions.x * this.getLevelScale(level); var widthScaled = this.dimensions.x * this.getLevelScale(level);
var pixelX = point.x * widthScaled; var pixelX = point.x * widthScaled;