diff --git a/src/rectangle.js b/src/rectangle.js index 5d3495af..abf1c947 100644 --- a/src/rectangle.js +++ b/src/rectangle.js @@ -201,6 +201,21 @@ $.Rect.prototype = /** @lends OpenSeadragon.Rect.prototype */{ ); }, + /** + * Translate/move this Rect by a vector and return new Rect. + * @function + * @param {OpenSeadragon.Point} delta The translation vector. + * @returns {OpenSeadragon.Rect} A new rect with altered position + */ + translate: function( delta ) { + return new OpenSeadragon.Rect( + this.x + delta.x, + this.y + delta.y, + this.width, + this.height + ); + }, + /** * Returns the smallest rectangle that will contain this and the given rectangle. * @param {OpenSeadragon.Rect} rect diff --git a/src/tiledimage.js b/src/tiledimage.js index d349658e..f2059eba 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1327,6 +1327,12 @@ function drawTiles( tiledImage, lastDrawn ) { var box = tiledImage.imageToViewportRectangle(tiledImage._clip, true); var clipRect = tiledImage._drawer.viewportToDrawerRectangle(box); + if (sketchScale) { + clipRect = clipRect.times(sketchScale); + } + if (sketchTranslate) { + clipRect = clipRect.translate(sketchTranslate); + } tiledImage._drawer.setClip(clipRect, useSketch); usedClip = true; @@ -1334,6 +1340,12 @@ function drawTiles( tiledImage, lastDrawn ) { if ( tiledImage.placeholderFillStyle && tiledImage._hasOpaqueTile === false ) { var placeholderRect = tiledImage._drawer.viewportToDrawerRectangle(tiledImage.getBounds(true)); + if (sketchScale) { + placeholderRect = placeholderRect.times(sketchScale); + } + if (sketchTranslate) { + placeholderRect = placeholderRect.translate(sketchTranslate); + } var fillStyle = null; if ( typeof tiledImage.placeholderFillStyle === "function" ) {