From bac2cab8e948f54d24af09e5be94712dacca8daa Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Wed, 2 Nov 2016 20:45:33 -0400 Subject: [PATCH 01/10] document tiledImage.preload --- src/openseadragon.js | 4 ++++ src/tiledimage.js | 20 +++++++++++++++++++- src/viewer.js | 7 ++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index bd252e1c..fac2dc98 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -187,6 +187,9 @@ * @property {Number} [opacity=1] * Default opacity of the tiled images (1=opaque, 0=transparent) * + * @property {Boolean} [preload=false] + * If true, tiles in image load without drawing. Defaults to false, so tiles are loaded and drawn. + * * @property {String} [compositeOperation=null] * Valid values are 'source-over', 'source-atop', 'source-in', 'source-out', * 'destination-over', 'destination-atop', 'destination-in', @@ -1081,6 +1084,7 @@ function OpenSeadragon( options ){ // APPEARANCE opacity: 1, + preload: false, compositeOperation: null, placeholderFillStyle: null, diff --git a/src/tiledimage.js b/src/tiledimage.js index e8092083..4f3d477c 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -71,6 +71,7 @@ * @param {Number} [options.smoothTileEdgesMinZoom] - See {@link OpenSeadragon.Options}. * @param {Boolean} [options.iOSDevice] - See {@link OpenSeadragon.Options}. * @param {Number} [options.opacity=1] - Opacity the tiled image should be drawn at. + * @param {Boolean} [options.preload=false] - If true, tiles in image load without drawing. Defaults to false, so tiles are loaded and drawn. * @param {String} [options.compositeOperation] - How the image is composited onto other images; see compositeOperation in {@link OpenSeadragon.Options} for possible values. * @param {Boolean} [options.debugMode] - See {@link OpenSeadragon.Options}. * @param {String|CanvasGradient|CanvasPattern|Function} [options.placeholderFillStyle] - See {@link OpenSeadragon.Options}. @@ -162,6 +163,7 @@ $.TiledImage = function( options ) { crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy, placeholderFillStyle: $.DEFAULT_SETTINGS.placeholderFillStyle, opacity: $.DEFAULT_SETTINGS.opacity, + preload: $.DEFAULT_SETTINGS.preload, compositeOperation: $.DEFAULT_SETTINGS.compositeOperation }, options ); @@ -290,7 +292,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * Draws the TiledImage to its Drawer. */ draw: function() { - if (this.opacity !== 0) { + if (this.opacity !== 0 && !this.preload) { this._midDraw = true; this._updateViewport(); this._midDraw = false; @@ -767,6 +769,22 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag this._needsDraw = true; }, + /** + * @returns {Boolean} whether the tiledImage is set to load tiles without drawing them. + */ + getPreload: function() { + return this.preload; + }, + + /** + * Set true to load without drawing. Set false for default loading and drawing. + * @param {Boolean} whether to load tiles without drawing in this tiledImage. + */ + setPreload: function(preload) { + this.preload = Boolean(preload); + this._needsDraw = true; + }, + /** * Get the current rotation of this tiled image in degrees. * @returns {Number} the current rotation of this tiled image in degrees. diff --git a/src/viewer.js b/src/viewer.js index 06b224e0..4d2a7358 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1227,7 +1227,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @param {OpenSeadragon.Rect} [options.clip] - An area, in image pixels, to clip to * (portions of the image outside of this area will not be visible). Only works on * browsers that support the HTML5 canvas. - * @param {Number} [options.opacity] Opacity the tiled image should be drawn at by default. + * @param {Number} [options.opacity=1] Opacity the tiled image should be drawn at by default. + * @param {Boolean} [options.preload=false] If true, tiles in image load without drawing by default. * @param {Number} [options.degrees=0] Initial rotation of the tiled image around * its top left corner in degrees. * @param {String} [options.compositeOperation] How the image is composited onto other images. @@ -1265,6 +1266,9 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, if (options.opacity === undefined) { options.opacity = this.opacity; } + if (options.preload === undefined) { + options.preload = this.preload; + } if (options.compositeOperation === undefined) { options.compositeOperation = this.compositeOperation; } @@ -1371,6 +1375,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, clip: queueItem.options.clip, placeholderFillStyle: queueItem.options.placeholderFillStyle, opacity: queueItem.options.opacity, + preload: queueItem.options.preload, degrees: queueItem.options.degrees, compositeOperation: queueItem.options.compositeOperation, springStiffness: _this.springStiffness, From 1baf086e1bd7c4251c436fe5ab84454c5962c244 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Thu, 3 Nov 2016 17:11:22 -0400 Subject: [PATCH 02/10] setting booleans the easy way --- src/tiledimage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index 4f3d477c..bff8603a 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -781,7 +781,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * @param {Boolean} whether to load tiles without drawing in this tiledImage. */ setPreload: function(preload) { - this.preload = Boolean(preload); + this.preload = (true == preload); this._needsDraw = true; }, From 3fc1948a4446fdf57c066f40adecfd3589ccda18 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Thu, 3 Nov 2016 17:12:44 -0400 Subject: [PATCH 03/10] setting booleans the shortest way --- src/tiledimage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index bff8603a..99a7c1f6 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -781,7 +781,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * @param {Boolean} whether to load tiles without drawing in this tiledImage. */ setPreload: function(preload) { - this.preload = (true == preload); + this.preload = !!preload; this._needsDraw = true; }, From 0a44585457a53a564e94e5b486aa3a378a1e480c Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Thu, 3 Nov 2016 22:39:00 -0400 Subject: [PATCH 04/10] documentation of opacity and preload relations --- src/openseadragon.js | 5 +++-- src/tiledimage.js | 10 +++++----- src/viewer.js | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index fac2dc98..cdaee4e5 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -185,10 +185,11 @@ * If 0, adjusts to fit viewer. * * @property {Number} [opacity=1] - * Default opacity of the tiled images (1=opaque, 0=transparent) + * Default proportional opacity of the tiled images (1=opaque, 0=hidden) + * Hidden images do not draw and only load when preloading is allowed. * * @property {Boolean} [preload=false] - * If true, tiles in image load without drawing. Defaults to false, so tiles are loaded and drawn. + * Default switch for loading hidden images (true loads, false blocks) * * @property {String} [compositeOperation=null] * Valid values are 'source-over', 'source-atop', 'source-in', 'source-out', diff --git a/src/tiledimage.js b/src/tiledimage.js index 99a7c1f6..11d96928 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -70,8 +70,8 @@ * @param {Number} [options.minPixelRatio] - See {@link OpenSeadragon.Options}. * @param {Number} [options.smoothTileEdgesMinZoom] - See {@link OpenSeadragon.Options}. * @param {Boolean} [options.iOSDevice] - See {@link OpenSeadragon.Options}. - * @param {Number} [options.opacity=1] - Opacity the tiled image should be drawn at. - * @param {Boolean} [options.preload=false] - If true, tiles in image load without drawing. Defaults to false, so tiles are loaded and drawn. + * @param {Number} [options.opacity=1] - Set to draw at proportional opacity. If zero, images will not draw. + * @param {Boolean} [options.preload=false] - Set true to load even when the image is hidden by zero opacity. * @param {String} [options.compositeOperation] - How the image is composited onto other images; see compositeOperation in {@link OpenSeadragon.Options} for possible values. * @param {Boolean} [options.debugMode] - See {@link OpenSeadragon.Options}. * @param {String|CanvasGradient|CanvasPattern|Function} [options.placeholderFillStyle] - See {@link OpenSeadragon.Options}. @@ -770,15 +770,15 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag }, /** - * @returns {Boolean} whether the tiledImage is set to load tiles without drawing them. + * @returns {Boolean} whether the tiledImage can load hidden tiles of zero opacity. */ getPreload: function() { return this.preload; }, /** - * Set true to load without drawing. Set false for default loading and drawing. - * @param {Boolean} whether to load tiles without drawing in this tiledImage. + * Set true to load even when hidden. Set false to block loading when hidden. + * @param {Boolean} whether the tiledImage can load hidden tiles of zero opacity. */ setPreload: function(preload) { this.preload = !!preload; diff --git a/src/viewer.js b/src/viewer.js index 4d2a7358..78357873 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1227,8 +1227,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @param {OpenSeadragon.Rect} [options.clip] - An area, in image pixels, to clip to * (portions of the image outside of this area will not be visible). Only works on * browsers that support the HTML5 canvas. - * @param {Number} [options.opacity=1] Opacity the tiled image should be drawn at by default. - * @param {Boolean} [options.preload=false] If true, tiles in image load without drawing by default. + * @param {Number} [options.opacity=1] Default proportional opacity of the tiled images (1=opaque, 0=hidden) + * @param {Boolean} [options.preload=false] Default switch for loading hidden images (true loads, false blocks) * @param {Number} [options.degrees=0] Initial rotation of the tiled image around * its top left corner in degrees. * @param {String} [options.compositeOperation] How the image is composited onto other images. From c402a7bfdd92b8f8e0da62e19e6a4b3202b439b4 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Fri, 4 Nov 2016 09:11:46 -0400 Subject: [PATCH 05/10] underscores to preload --- src/tiledimage.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index 11d96928..dbb2e4fe 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -163,7 +163,7 @@ $.TiledImage = function( options ) { crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy, placeholderFillStyle: $.DEFAULT_SETTINGS.placeholderFillStyle, opacity: $.DEFAULT_SETTINGS.opacity, - preload: $.DEFAULT_SETTINGS.preload, + _preload: $.DEFAULT_SETTINGS.preload, compositeOperation: $.DEFAULT_SETTINGS.compositeOperation }, options ); @@ -292,7 +292,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * Draws the TiledImage to its Drawer. */ draw: function() { - if (this.opacity !== 0 && !this.preload) { + if (this.opacity !== 0 && !this._preload) { this._midDraw = true; this._updateViewport(); this._midDraw = false; @@ -773,15 +773,14 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * @returns {Boolean} whether the tiledImage can load hidden tiles of zero opacity. */ getPreload: function() { - return this.preload; + return this._preload; }, /** * Set true to load even when hidden. Set false to block loading when hidden. - * @param {Boolean} whether the tiledImage can load hidden tiles of zero opacity. */ setPreload: function(preload) { - this.preload = !!preload; + this._preload = !!preload; this._needsDraw = true; }, From 171591a7a37e9f8b6414f9e90bad4470f2f1beb7 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Fri, 4 Nov 2016 09:21:04 -0400 Subject: [PATCH 06/10] new opacity flag --- src/tiledimage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index dbb2e4fe..5a763ecd 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1533,7 +1533,7 @@ function compareTiles( previousBest, tile ) { } function drawTiles( tiledImage, lastDrawn ) { - if (lastDrawn.length === 0) { + if (this.opacity == 0 || lastDrawn.length === 0) { return; } var tile = lastDrawn[0]; From 9548ad6a27601365e837616d484405deb782ccd8 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Fri, 4 Nov 2016 09:24:08 -0400 Subject: [PATCH 07/10] using the strict === comparison --- src/tiledimage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index 5a763ecd..18ca5917 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -1533,7 +1533,7 @@ function compareTiles( previousBest, tile ) { } function drawTiles( tiledImage, lastDrawn ) { - if (this.opacity == 0 || lastDrawn.length === 0) { + if (this.opacity === 0 || lastDrawn.length === 0) { return; } var tile = lastDrawn[0]; From 2915ee09c5d953942afbf6f8a9bc5c8e8d33bf09 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Fri, 4 Nov 2016 09:26:34 -0400 Subject: [PATCH 08/10] correct logic for call to _updateViewport --- src/tiledimage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index 18ca5917..d9067229 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -292,7 +292,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * Draws the TiledImage to its Drawer. */ draw: function() { - if (this.opacity !== 0 && !this._preload) { + if (!(this.opacity === 0 && !this._preload)) { this._midDraw = true; this._updateViewport(); this._midDraw = false; From cf5825d1fa3a223c4504ce0e7395a649bf6e8144 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Fri, 4 Nov 2016 10:03:04 -0400 Subject: [PATCH 09/10] better underscores in preload term handling --- src/tiledimage.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index d9067229..f6337c59 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -163,10 +163,13 @@ $.TiledImage = function( options ) { crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy, placeholderFillStyle: $.DEFAULT_SETTINGS.placeholderFillStyle, opacity: $.DEFAULT_SETTINGS.opacity, - _preload: $.DEFAULT_SETTINGS.preload, + preload: $.DEFAULT_SETTINGS.preload, compositeOperation: $.DEFAULT_SETTINGS.compositeOperation }, options ); + this._preload = this.preload; + delete this.preload; + this._fullyLoaded = false; this._xSpring = new $.Spring({ From 7a4fda37b57808720454fcaab9780a2eea4caf25 Mon Sep 17 00:00:00 2001 From: thejohnhoffer Date: Tue, 30 May 2017 12:00:43 -0500 Subject: [PATCH 10/10] setPreload correctly treats both Primatives and Objects as Boolean Primatives --- src/tiledimage.js | 8 ++++---- src/viewer.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tiledimage.js b/src/tiledimage.js index f6337c59..bfedc96d 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -295,7 +295,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * Draws the TiledImage to its Drawer. */ draw: function() { - if (!(this.opacity === 0 && !this._preload)) { + if (this.opacity !== 0 || this._preload) { this._midDraw = true; this._updateViewport(); this._midDraw = false; @@ -773,7 +773,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag }, /** - * @returns {Boolean} whether the tiledImage can load hidden tiles of zero opacity. + * @returns {Boolean} whether the tiledImage can load its tiles even when it has zero opacity. */ getPreload: function() { return this._preload; @@ -783,7 +783,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag * Set true to load even when hidden. Set false to block loading when hidden. */ setPreload: function(preload) { - this._preload = !!preload; + this._preload = new Boolean(preload).valueOf(); this._needsDraw = true; }, @@ -1536,7 +1536,7 @@ function compareTiles( previousBest, tile ) { } function drawTiles( tiledImage, lastDrawn ) { - if (this.opacity === 0 || lastDrawn.length === 0) { + if (tiledImage.opacity === 0 || lastDrawn.length === 0) { return; } var tile = lastDrawn[0]; diff --git a/src/viewer.js b/src/viewer.js index 78357873..2c97d31a 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1227,7 +1227,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @param {OpenSeadragon.Rect} [options.clip] - An area, in image pixels, to clip to * (portions of the image outside of this area will not be visible). Only works on * browsers that support the HTML5 canvas. - * @param {Number} [options.opacity=1] Default proportional opacity of the tiled images (1=opaque, 0=hidden) + * @param {Number} [options.opacity=1] Proportional opacity of the tiled images (1=opaque, 0=hidden) * @param {Boolean} [options.preload=false] Default switch for loading hidden images (true loads, false blocks) * @param {Number} [options.degrees=0] Initial rotation of the tiled image around * its top left corner in degrees.