mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
add documentation; remove unnecessary deprecated code
This commit is contained in:
parent
3a5a738508
commit
cc412f0a20
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -61,7 +61,7 @@ class HTMLDrawer extends $.DrawerBase{
|
||||
/**
|
||||
* @returns {Boolean} always true
|
||||
*/
|
||||
isSupported(){
|
||||
static isSupported(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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' );
|
||||
|
@ -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;
|
||||
|
@ -16,7 +16,7 @@
|
||||
// debugMode: true,
|
||||
zoomPerScroll: 1.02,
|
||||
showNavigator: testNavigator,
|
||||
drawer: ['context2d', 'html'],
|
||||
drawer: ['canvas', 'html'],
|
||||
// defaultZoomLevel: 2,
|
||||
// homeFillsViewer: true,
|
||||
// sequenceMode: true,
|
||||
|
@ -65,7 +65,7 @@
|
||||
<div class="mirrored">
|
||||
<div>
|
||||
<h3>Context2d drawer (default in OSD <= 4.1.0)</h3>
|
||||
<div id="context2d" class="viewer-container"></div>
|
||||
<div id="canvasdrawer" class="viewer-container"></div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
@ -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
|
||||
});
|
||||
|
||||
|
@ -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' );
|
||||
|
@ -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;
|
||||
|
||||
|
@ -45,9 +45,9 @@
|
||||
// if ( viewer && viewer.close ) {
|
||||
// viewer.close();
|
||||
// }
|
||||
// if (viewer && viewer.destroy){
|
||||
// viewer.destroy();
|
||||
// }
|
||||
if (viewer && viewer.destroy){
|
||||
viewer.destroy();
|
||||
}
|
||||
|
||||
viewer = null;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user