diff --git a/src/context2ddrawer.js b/src/context2ddrawer.js index b07d9411..4516856c 100644 --- a/src/context2ddrawer.js +++ b/src/context2ddrawer.js @@ -81,7 +81,7 @@ class Context2dDrawer extends $.DrawerBase{ /** * @returns {Boolean} true if canvas is supported by the browser, otherwise false */ - isSupported(){ + static isSupported(){ return $.supportsCanvas; } diff --git a/src/drawerbase.js b/src/drawerbase.js index 93dbcf1b..245e6939 100644 --- a/src/drawerbase.js +++ b/src/drawerbase.js @@ -76,11 +76,6 @@ $.DrawerBase = class DrawerBase{ this.debugGridColor = typeof options.debugGridColor === 'string' ? [options.debugGridColor] : options.debugGridColor || $.DEFAULT_SETTINGS.debugGridColor; this.options = options.options || {}; - // TO DO: This was deprectated previously. Can we get rid of it at this point? - if (options.opacity) { - $.console.error( "[Drawer] options.opacity is no longer accepted; set the opacity on the TiledImage instead" ); - } - /** * The parent element of this Drawer instance, passed in when the Drawer was created. * The parent of {@link OpenSeadragon.DrawerBase#canvas}. @@ -130,7 +125,7 @@ $.DrawerBase = class DrawerBase{ /** * @returns {Boolean} whether the drawer implementation is supported by the browser */ - isSupported() { + static isSupported() { $.console.error('Drawer.isSupported must be implemented by child class'); } @@ -221,7 +216,7 @@ $.DrawerBase = class DrawerBase{ /** * This event is fired just before the tile is drawn giving the application a chance to alter the image. * - * NOTE: This event is only fired in certain drawing contexts: either the 'context2d' drawer is + * NOTE: This event is only fired in certain drawing contexts: either the 'canvas' drawer is * being used, or the 'webgl' drawer with 'drawerOptions.webgl.continuousTileRefresh'. * * @event tile-drawing diff --git a/src/htmldrawer.js b/src/htmldrawer.js index 1b3306fa..20117b40 100644 --- a/src/htmldrawer.js +++ b/src/htmldrawer.js @@ -61,7 +61,7 @@ class HTMLDrawer extends $.DrawerBase{ /** * @returns {Boolean} always true */ - isSupported(){ + static isSupported(){ return true; } diff --git a/src/imagetilesource.js b/src/imagetilesource.js index 4596b2c0..b039cc2b 100644 --- a/src/imagetilesource.js +++ b/src/imagetilesource.js @@ -195,6 +195,8 @@ /** * Destroys ImageTileSource * @function + * @param {OpenSeadragon.Viewer} viewer the viewer that is calling + * destroy on the ImageTileSource */ destroy: function (viewer) { this._freeupCanvasMemory(viewer); @@ -273,17 +275,20 @@ this.levels[i].context2D.canvas.height = 0; this.levels[i].context2D.canvas.width = 0; - /** - * Triggered when an image has just been unloaded - * - * @event image-unloaded - * @memberof OpenSeadragon.Viewer - * @type {object} - * @property {CanvasRenderingContext2D} context2D - The context that is being unloaded - */ - viewer.raiseEvent("image-unloaded", { - context2D: this.levels[i].context2D - }); + if(viewer){ + /** + * Triggered when an image has just been unloaded + * + * @event image-unloaded + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {CanvasRenderingContext2D} context2D - The context that is being unloaded + */ + viewer.raiseEvent("image-unloaded", { + context2D: this.levels[i].context2D + }); + } + } } }, diff --git a/src/openseadragon.js b/src/openseadragon.js index 1e6f1d75..cfa80df5 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -190,8 +190,8 @@ * Zoom level to use when image is first opened or the home button is clicked. * If 0, adjusts to fit viewer. * - * @property {String|DrawerImplementation|Array} [drawer = ['webgl', 'context2d', 'html']] - * Which drawer to use. Valid strings are 'context2d' and 'html'. Valid drawer + * @property {String|DrawerImplementation|Array} [drawer = ['webgl', 'canvas', 'html']] + * Which drawer to use. Valid strings are 'webgl', 'canvas', and 'html'. Valid drawer * implementations are constructors of classes that extend OpenSeadragon.DrawerBase. * An array of strings and/or constructors can be used to indicate the priority * of different implementations, which will be tried in order based on browser support. @@ -1346,8 +1346,7 @@ function OpenSeadragon( options ){ compositeOperation: null, // to be passed into each TiledImage // DRAWER SETTINGS - drawer: ['webgl', 'context2d', 'html'], // prefer using webgl, context2d, fallback to html - useCanvas: true, // deprecated - set drawer and drawerOptions + drawer: ['webgl', 'canvas', 'html'], // prefer using webgl, context2d, fallback to html /** * drawerOptions dictionary. * @type {Object} drawerOptions diff --git a/src/tilesource.js b/src/tilesource.js index ea861919..4961a47f 100644 --- a/src/tilesource.js +++ b/src/tilesource.js @@ -423,41 +423,6 @@ $.TileSource.prototype = { return new $.Rect( px * scale, py * scale, sx * scale, sy * scale ); }, - /** - * @function - * @param {Number} level - * @param {Number} x - * @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 unless imageCoordinates == true) or the - * portion of the tile to use as the source of the drawing operation (in pixels), depending on - * the isSource parameter, without overlap. - */ - getTileBoundsNoOverlap: function( level, x, y, isSource, imageCoordinates ) { - var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ), - tileWidth = this.getTileWidth(level), - tileHeight = this.getTileHeight(level), - tileOverlap = this.tileOverlap || 0, - px = tileWidth * x, - py = tileHeight * y, - sx = tileWidth, - sy = tileHeight, - scale = 1.0 / dimensionsScaled.x; - - sx = Math.min( sx, dimensionsScaled.x - px ); - sy = Math.min( sy, dimensionsScaled.y - py ); - - if (isSource) { - return new $.Rect((x === 0 ? 0 : tileOverlap), (y === 0 ? 0 : tileOverlap), sx, sy); - } else if ( imageCoordinates ){ - return new $.Rect( px, py, sx, sy).times(scale * this.width); - } else { - return new $.Rect( px, py, sx, sy).times(scale); - } - - - }, - /** * Responsible for retrieving, and caching the diff --git a/src/viewer.js b/src/viewer.js index bcb7cc94..f39e6251 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -446,7 +446,7 @@ $.Viewer = function( options ) { delete this.drawerOptions.useCanvas; } let drawerPriority = Array.isArray(this.drawer) ? this.drawer : [this.drawer]; - let drawersToTry = drawerPriority.filter(d => ['webgl', 'context2d', 'html'].includes(d) || (d.prototype && d.prototype.isOpenSeadragonDrawer) ); + let drawersToTry = drawerPriority.filter(d => ['webgl', 'canvas', 'html'].includes(d) || (d.prototype && d.prototype.isOpenSeadragonDrawer) ); if(drawerPriority.length !== drawersToTry.length){ $.console.error('An invalid drawer was requested.'); } @@ -460,9 +460,9 @@ $.Viewer = function( options ) { let Drawer = drawersToTry[i]; let optsKey = null; // replace text-based option with appropriate constructor - if (Drawer === 'context2d'){ + if (Drawer === 'canvas'){ Drawer = $.Context2dDrawer; - optsKey = 'context2d'; + optsKey = 'canvas'; } else if (Drawer === 'html'){ Drawer = $.HTMLDrawer; optsKey = 'html'; @@ -473,7 +473,7 @@ $.Viewer = function( options ) { optsKey = 'custom'; } // if the drawer is supported, create it and break the loop - if (Drawer.prototype.isSupported()){ + if (Drawer.isSupported()){ this.drawer = new Drawer({ viewer: this, viewport: this.viewport, diff --git a/src/webgldrawer.js b/src/webgldrawer.js index e61ac8fd..5b98f56b 100644 --- a/src/webgldrawer.js +++ b/src/webgldrawer.js @@ -234,10 +234,10 @@ // Public API required by all Drawer implementations /** - * @returns {Boolean} returns true if canvas and webgl are supported and - * three.js has been exposed as a global variable named THREE - */ - isSupported(){ + * @returns {Boolean} returns true if canvas and webgl are supported and + * three.js has been exposed as a global variable named THREE + */ + static isSupported(){ let canvasElement = document.createElement( 'canvas' ); let webglContext = $.isFunction( canvasElement.getContext ) && canvasElement.getContext( 'webgl' ); diff --git a/src/world.js b/src/world.js index 30e9fc48..fa459317 100644 --- a/src/world.js +++ b/src/world.js @@ -242,6 +242,9 @@ $.extend( $.World.prototype, $.EventSource.prototype, /** @lends OpenSeadragon.W /** * Updates (i.e. animates bounds of) all items. + * @function + * @param viewportChanged Whether the viewport changed, which indicates that + * all TiledImages need to be updated. */ update: function(viewportChanged) { var animated = false; diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index b5cf86ca..0806bedc 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -16,7 +16,7 @@ // debugMode: true, zoomPerScroll: 1.02, showNavigator: testNavigator, - drawer: ['context2d', 'html'], + drawer: ['canvas', 'html'], // defaultZoomLevel: 2, // homeFillsViewer: true, // sequenceMode: true, diff --git a/test/demo/drawercomparison.html b/test/demo/drawercomparison.html index ad82b6f6..99c2b946 100644 --- a/test/demo/drawercomparison.html +++ b/test/demo/drawercomparison.html @@ -65,7 +65,7 @@

Context2d drawer (default in OSD <= 4.1.0)

-
+
diff --git a/test/demo/drawercomparison.js b/test/demo/drawercomparison.js index 2199c2b6..7edb0101 100644 --- a/test/demo/drawercomparison.js +++ b/test/demo/drawercomparison.js @@ -15,9 +15,9 @@ const labels = { } //Double viewer setup for comparison - Context2dDrawer and WebGLDrawer -// viewer1: context2d drawer +// viewer1: canvas drawer let viewer1 = window.viewer1 = OpenSeadragon({ - id: "context2d", + id: "canvasdrawer", prefixUrl: "../../build/openseadragon/images/", minZoomImageRatio:0.01, maxZoomPixelRatio:100, @@ -25,7 +25,7 @@ let viewer1 = window.viewer1 = OpenSeadragon({ crossOriginPolicy: 'Anonymous', ajaxWithCredentials: false, // maxImageCacheCount: 30, - drawer:'context2d', + drawer:'canvas', blendTime:0 }); diff --git a/test/demo/webgldemodrawer.js b/test/demo/webgldemodrawer.js index 41346f7a..61e7c13c 100644 --- a/test/demo/webgldemodrawer.js +++ b/test/demo/webgldemodrawer.js @@ -238,10 +238,10 @@ // Public API required by all Drawer implementations /** - * @returns {Boolean} returns true if canvas and webgl are supported and - * three.js has been exposed as a global variable named THREE - */ - isSupported(){ + * @returns {Boolean} returns true if canvas and webgl are supported and + * three.js has been exposed as a global variable named THREE + */ + static isSupported(){ let canvasElement = document.createElement( 'canvas' ); let webglContext = $.isFunction( canvasElement.getContext ) && canvasElement.getContext( 'webgl' ); diff --git a/test/modules/drawer.js b/test/modules/drawer.js index e4f507a3..ad953080 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -45,7 +45,7 @@ var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi', - drawer: 'context2d', // this test only makes sense for certain drawers + drawer: 'canvas', // this test only makes sense for certain drawers }); viewer.addHandler('open', function handler(event) { @@ -76,7 +76,7 @@ var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi', - drawer: 'context2d' // test only makes sense for this drawer + drawer: 'canvas' // test only makes sense for this drawer }); var drawer = viewer.drawer; diff --git a/test/modules/navigator.js b/test/modules/navigator.js index 1523fa63..ab1be8d3 100644 --- a/test/modules/navigator.js +++ b/test/modules/navigator.js @@ -45,9 +45,9 @@ // if ( viewer && viewer.close ) { // viewer.close(); // } - // if (viewer && viewer.destroy){ - // viewer.destroy(); - // } + if (viewer && viewer.destroy){ + viewer.destroy(); + } viewer = null; } diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js index e9675356..123ff890 100644 --- a/test/modules/tiledimage.js +++ b/test/modules/tiledimage.js @@ -135,7 +135,7 @@ QUnit.test('update', function(assert) { var done = assert.async(); var handlerCount = 0; - var testTileDrawingEvent = viewer.drawerOptions.type === 'context2d'; + var testTileDrawingEvent = viewer.drawerOptions.type === 'canvas'; let expectedHandlers = testTileDrawingEvent ? 4 : 3; viewer.addHandler('open', function(event) {