Now supporting square edge tiles with padding

This commit is contained in:
Ian Gilman 2018-03-21 14:07:00 -07:00
parent dccd038f6c
commit 075a37ce8c
4 changed files with 5897 additions and 8 deletions

5862
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -40,7 +40,7 @@
* @param {Number} level The zoom level this tile belongs to. * @param {Number} level The zoom level this tile belongs to.
* @param {Number} x The vector component 'x'. * @param {Number} x The vector component 'x'.
* @param {Number} y The vector component 'y'. * @param {Number} y The vector component 'y'.
* @param {OpenSeadragon.Point} bounds Where this tile fits, in normalized * @param {OpenSeadragon.Rect} bounds Where this tile fits, in normalized
* coordinates. * coordinates.
* @param {Boolean} exists Is this tile a part of a sparse image? ( Also has * @param {Boolean} exists Is this tile a part of a sparse image? ( Also has
* this tile failed to load? ) * this tile failed to load? )
@ -49,8 +49,11 @@
* is provided directly by the tile source. * is provided directly by the tile source.
* @param {Boolean} loadWithAjax Whether this tile image should be loaded with an AJAX request . * @param {Boolean} loadWithAjax Whether this tile image should be loaded with an AJAX request .
* @param {Object} ajaxHeaders The headers to send with this tile's AJAX request (if applicable). * @param {Object} ajaxHeaders The headers to send with this tile's AJAX request (if applicable).
* @param {OpenSeadragon.Rect} sourceBounds The portion of the tile to use as the source of the
* drawing operation, in pixels. Note that this only works when drawing with canvas; when drawing
* with HTML the entire tile is always used.
*/ */
$.Tile = function(level, x, y, bounds, exists, url, context2D, loadWithAjax, ajaxHeaders) { $.Tile = function(level, x, y, bounds, exists, url, context2D, loadWithAjax, ajaxHeaders, sourceBounds) {
/** /**
* The zoom level this tile belongs to. * The zoom level this tile belongs to.
* @member {Number} level * @member {Number} level
@ -75,6 +78,13 @@ $.Tile = function(level, x, y, bounds, exists, url, context2D, loadWithAjax, aja
* @memberof OpenSeadragon.Tile# * @memberof OpenSeadragon.Tile#
*/ */
this.bounds = bounds; this.bounds = bounds;
/**
* The portion of the tile to use as the source of the drawing operation, in pixels. Note that
* this only works when drawing with canvas; when drawing with HTML the entire tile is always used.
* @member {OpenSeadragon.Rect} sourceBounds
* @memberof OpenSeadragon.Tile#
*/
this.sourceBounds = sourceBounds;
/** /**
* Is this tile a part of a sparse image? Also has this tile failed to load? * Is this tile a part of a sparse image? Also has this tile failed to load?
* @member {Boolean} exists * @member {Boolean} exists
@ -357,12 +367,16 @@ $.Tile.prototype = {
// changes as we are rendering the image // changes as we are rendering the image
drawingHandler({context: context, tile: this, rendered: rendered}); drawingHandler({context: context, tile: this, rendered: rendered});
if (!this.sourceBounds) { // Just in case
this.sourceBounds = new $.Rect(0, 0, rendered.canvas.width, rendered.canvas.height);
}
context.drawImage( context.drawImage(
rendered.canvas, rendered.canvas,
0, this.sourceBounds.x,
0, this.sourceBounds.y,
rendered.canvas.width, this.sourceBounds.width,
rendered.canvas.height, this.sourceBounds.height,
position.x, position.x,
position.y, position.y,
size.x, size.x,

View File

@ -1372,6 +1372,7 @@ function getTile(
var xMod, var xMod,
yMod, yMod,
bounds, bounds,
sourceBounds,
exists, exists,
url, url,
ajaxHeaders, ajaxHeaders,
@ -1389,6 +1390,7 @@ function getTile(
xMod = ( numTiles.x + ( x % numTiles.x ) ) % numTiles.x; xMod = ( numTiles.x + ( x % numTiles.x ) ) % numTiles.x;
yMod = ( numTiles.y + ( y % numTiles.y ) ) % numTiles.y; yMod = ( numTiles.y + ( y % numTiles.y ) ) % numTiles.y;
bounds = tileSource.getTileBounds( level, xMod, yMod ); bounds = tileSource.getTileBounds( level, xMod, yMod );
sourceBounds = tileSource.getTileBounds( level, xMod, yMod, true );
exists = tileSource.tileExists( level, xMod, yMod ); exists = tileSource.tileExists( level, xMod, yMod );
url = tileSource.getTileUrl( level, xMod, yMod ); url = tileSource.getTileUrl( level, xMod, yMod );
@ -1418,7 +1420,8 @@ function getTile(
url, url,
context2D, context2D,
tiledImage.loadTilesWithAjax, tiledImage.loadTilesWithAjax,
ajaxHeaders ajaxHeaders,
sourceBounds
); );
if (xMod === numTiles.x - 1) { if (xMod === numTiles.x - 1) {

View File

@ -373,8 +373,12 @@ $.TileSource.prototype = {
* @param {Number} level * @param {Number} level
* @param {Number} x * @param {Number} x
* @param {Number} y * @param {Number} y
* @param {Boolean} [isSource=false] Whether to return the source bounds of the tile.
* @returns {OpenSeadragon.Rect} Either where this tile fits (in normalized coordinates) or the
* portion of the tile to use as the source of the drawing operation (in pixels), depending on
* the isSource parameter.
*/ */
getTileBounds: function( level, x, y ) { getTileBounds: function( level, x, y, isSource ) {
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ), var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
tileWidth = this.getTileWidth(level), tileWidth = this.getTileWidth(level),
tileHeight = this.getTileHeight(level), tileHeight = this.getTileHeight(level),
@ -387,6 +391,12 @@ $.TileSource.prototype = {
sx = Math.min( sx, dimensionsScaled.x - px ); sx = Math.min( sx, dimensionsScaled.x - px );
sy = Math.min( sy, dimensionsScaled.y - py ); sy = Math.min( sy, dimensionsScaled.y - py );
if (isSource) {
scale = 1;
px = 0;
py = 0;
}
return new $.Rect( px * scale, py * scale, sx * scale, sy * scale ); return new $.Rect( px * scale, py * scale, sx * scale, sy * scale );
}, },