Further cleanup

This commit is contained in:
Ian Gilman 2014-08-11 17:04:20 -07:00
parent 94080c3180
commit 45b7118732
4 changed files with 30 additions and 110 deletions

View File

@ -34,19 +34,6 @@
(function( $ ){ (function( $ ){
var DEVICE_SCREEN = $.getWindowSize(),
BROWSER = $.Browser.vendor,
BROWSER_VERSION = $.Browser.version,
SUBPIXEL_RENDERING = (
( BROWSER == $.BROWSERS.FIREFOX ) ||
( BROWSER == $.BROWSERS.OPERA ) ||
( BROWSER == $.BROWSERS.SAFARI && BROWSER_VERSION >= 4 ) ||
( BROWSER == $.BROWSERS.CHROME && BROWSER_VERSION >= 2 ) ||
( BROWSER == $.BROWSERS.IE && BROWSER_VERSION >= 9 )
);
/** /**
* @class Drawer * @class Drawer
* @classdesc Handles rendering of tiles for an {@link OpenSeadragon.Viewer}. * @classdesc Handles rendering of tiles for an {@link OpenSeadragon.Viewer}.
@ -63,8 +50,7 @@ $.Drawer = function( options ) {
//backward compatibility for positional args while prefering more //backward compatibility for positional args while prefering more
//idiomatic javascript options object as the only argument //idiomatic javascript options object as the only argument
var args = arguments, var args = arguments;
i;
if( !$.isPlainObject( options ) ){ if( !$.isPlainObject( options ) ){
options = { options = {
@ -74,42 +60,15 @@ $.Drawer = function( options ) {
}; };
} }
$.console.assert( options.viewport, "[Drawer] options.viewport is required" );
$.console.assert( options.element, "[Drawer] options.element is required" );
if ( options.source ) { if ( options.source ) {
$.console.error( "[Drawer] options.source is no longer accepted; use TiledImage instead" ); $.console.error( "[Drawer] options.source is no longer accepted; use TiledImage instead" );
} }
$.extend( true, this, { this.viewer = options.viewer;
this.opacity = options.opacity === undefined ? $.DEFAULT_SETTINGS.opacity : options.opacity;
//internal state properties
viewer: null,
imageLoader: new $.ImageLoader(),
tilesMatrix: {}, // A '3d' dictionary [level][x][y] --> Tile.
tilesLoaded: [], // An unordered list of Tiles with loaded images.
coverage: {}, // A '3d' dictionary [level][x][y] --> Boolean.
lastDrawn: [], // An unordered list of Tiles drawn last frame.
lastResetTime: 0, // Last time for which the drawer was reset.
midUpdate: false, // Is the drawer currently updating the viewport?
updateAgain: true, // Does the drawer need to update the viewport again?
//internal state / configurable settings
collectionOverlays: {}, // For collection mode. Here an overlay is actually a viewer.
//configurable settings
opacity: $.DEFAULT_SETTINGS.opacity,
maxImageCacheCount: $.DEFAULT_SETTINGS.maxImageCacheCount,
minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio,
wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal,
wrapVertical: $.DEFAULT_SETTINGS.wrapVertical,
immediateRender: $.DEFAULT_SETTINGS.immediateRender,
blendTime: $.DEFAULT_SETTINGS.blendTime,
alwaysBlend: $.DEFAULT_SETTINGS.alwaysBlend,
minPixelRatio: $.DEFAULT_SETTINGS.minPixelRatio,
debugMode: $.DEFAULT_SETTINGS.debugMode,
timeout: $.DEFAULT_SETTINGS.timeout,
crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy
}, options );
this.useCanvas = $.supportsCanvas && ( this.viewer ? this.viewer.useCanvas : true ); this.useCanvas = $.supportsCanvas && ( this.viewer ? this.viewer.useCanvas : true );
/** /**
@ -118,7 +77,7 @@ $.Drawer = function( options ) {
* @member {Element} container * @member {Element} container
* @memberof OpenSeadragon.Drawer# * @memberof OpenSeadragon.Drawer#
*/ */
this.container = $.getElement( this.element ); this.container = $.getElement( options.element );
/** /**
* A <canvas> element if the browser supports them, otherwise a <div> element. * A <canvas> element if the browser supports them, otherwise a <div> element.
* Child element of {@link OpenSeadragon.Drawer#container}. * Child element of {@link OpenSeadragon.Drawer#container}.
@ -269,6 +228,7 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
getOpacity: function() { getOpacity: function() {
return this.opacity; return this.opacity;
}, },
/** /**
* Returns whether the Drawer is scheduled for an update at the * Returns whether the Drawer is scheduled for an update at the
* soonest possible opportunity. * soonest possible opportunity.
@ -277,7 +237,8 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* soonest possible opportunity. * soonest possible opportunity.
*/ */
needsUpdate: function() { needsUpdate: function() {
return this.updateAgain; $.console.error( "[Drawer.needsUpdate] this function is deprecated." );
return false;
}, },
/** /**
@ -287,7 +248,8 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* this Drawer. * this Drawer.
*/ */
numTilesLoaded: function() { numTilesLoaded: function() {
return this.tilesLoaded.length; $.console.error( "[Drawer.numTilesLoaded] this function is deprecated." );
return 0;
}, },
/** /**
@ -297,8 +259,7 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* @return {OpenSeadragon.Drawer} Chainable. * @return {OpenSeadragon.Drawer} Chainable.
*/ */
reset: function() { reset: function() {
this.lastResetTime = $.now(); $.console.error( "[Drawer.reset] this function is deprecated." );
this.updateAgain = true;
return this; return this;
}, },
@ -308,10 +269,7 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* @return {OpenSeadragon.Drawer} Chainable. * @return {OpenSeadragon.Drawer} Chainable.
*/ */
update: function() { update: function() {
//this.profiler.beginUpdate(); $.console.error( "[Drawer.update] this function is deprecated." );
this.midUpdate = true;
this.midUpdate = false;
//this.profiler.endUpdate();
return this; return this;
}, },
@ -330,11 +288,6 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* @return null * @return null
*/ */
destroy: function() { destroy: function() {
//unload current loaded tiles (=empty TILE_CACHE)
for ( var i = 0; i < this.tilesLoaded.length; ++i ) {
this.tilesLoaded[i].unload();
}
//force unloading of current canvas (1x1 will be gc later, trick not necessarily needed) //force unloading of current canvas (1x1 will be gc later, trick not necessarily needed)
this.canvas.width = 1; this.canvas.width = 1;
this.canvas.height = 1; this.canvas.height = 1;

View File

@ -44,6 +44,8 @@
$.TiledImage = function( options ) { $.TiledImage = function( options ) {
$.console.assert( options.tileCache, "[TiledImage] options.tileCache is required" ); $.console.assert( options.tileCache, "[TiledImage] options.tileCache is required" );
$.console.assert( options.drawer, "[TiledImage] options.drawer is required" ); $.console.assert( options.drawer, "[TiledImage] options.drawer is required" );
$.console.assert( options.viewer, "[TiledImage] options.viewer is required" );
$.console.assert( options.imageLoader, "[TiledImage] options.imageLoader is required" );
this._tileCache = options.tileCache; this._tileCache = options.tileCache;
delete options.tileCache; delete options.tileCache;
@ -51,6 +53,9 @@ $.TiledImage = function( options ) {
this._drawer = options.drawer; this._drawer = options.drawer;
delete options.drawer; delete options.drawer;
this._imageLoader = options.imageLoader;
delete options.imageLoader;
this._worldX = options.x || 0; this._worldX = options.x || 0;
delete options.x; delete options.x;
this._worldY = options.y || 0; this._worldY = options.y || 0;
@ -81,7 +86,6 @@ $.TiledImage = function( options ) {
//internal state properties //internal state properties
viewer: null, viewer: null,
imageLoader: new $.ImageLoader(),
tilesMatrix: {}, // A '3d' dictionary [level][x][y] --> Tile. tilesMatrix: {}, // A '3d' dictionary [level][x][y] --> Tile.
coverage: {}, // A '3d' dictionary [level][x][y] --> Boolean. coverage: {}, // A '3d' dictionary [level][x][y] --> Boolean.
lastDrawn: [], // An unordered list of Tiles drawn last frame. lastDrawn: [], // An unordered list of Tiles drawn last frame.
@ -89,13 +93,7 @@ $.TiledImage = function( options ) {
midUpdate: false, // Is the tiledImage currently updating the viewport? midUpdate: false, // Is the tiledImage currently updating the viewport?
updateAgain: true, // Does the tiledImage need to update the viewport again? updateAgain: true, // Does the tiledImage need to update the viewport again?
//internal state / configurable settings
collectionOverlays: {}, // For collection mode. Here an overlay is actually a viewer.
//configurable settings //configurable settings
opacity: $.DEFAULT_SETTINGS.opacity,
maxImageCacheCount: $.DEFAULT_SETTINGS.maxImageCacheCount,
minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio, minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio,
wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal, wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal,
wrapVertical: $.DEFAULT_SETTINGS.wrapVertical, wrapVertical: $.DEFAULT_SETTINGS.wrapVertical,
@ -104,34 +102,12 @@ $.TiledImage = function( options ) {
alwaysBlend: $.DEFAULT_SETTINGS.alwaysBlend, alwaysBlend: $.DEFAULT_SETTINGS.alwaysBlend,
minPixelRatio: $.DEFAULT_SETTINGS.minPixelRatio, minPixelRatio: $.DEFAULT_SETTINGS.minPixelRatio,
debugMode: $.DEFAULT_SETTINGS.debugMode, debugMode: $.DEFAULT_SETTINGS.debugMode,
timeout: $.DEFAULT_SETTINGS.timeout,
crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy
}, options ); }, options );
}; };
$.TiledImage.prototype = /** @lends OpenSeadragon.TiledImage.prototype */{ $.TiledImage.prototype = /** @lends OpenSeadragon.TiledImage.prototype */{
/**
* Set the opacity of the TiledImage.
* @method
* @param {Number} opacity
* @return {OpenSeadragon.TiledImage} Chainable.
*/
setOpacity: function( opacity ) {
this.opacity = opacity;
// TODO: trigger update
return this;
},
/**
* Get the opacity of the TiledImage.
* @method
* @returns {Number}
*/
getOpacity: function() {
return this.opacity;
},
/** /**
* Returns whether the TiledImage is scheduled for an update at the * Returns whether the TiledImage is scheduled for an update at the
* soonest possible opportunity. * soonest possible opportunity.
@ -558,7 +534,7 @@ function getTile( x, y, level, tileSource, tilesMatrix, time, numTiles, worldWid
function loadTile( tiledImage, tile, time ) { function loadTile( tiledImage, tile, time ) {
tile.loading = true; tile.loading = true;
tiledImage.imageLoader.addJob({ tiledImage._imageLoader.addJob({
src: tile.url, src: tile.url,
crossOriginPolicy: tiledImage.crossOriginPolicy, crossOriginPolicy: tiledImage.crossOriginPolicy,
callback: function( image ){ callback: function( image ){

View File

@ -1102,9 +1102,6 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
y: options.y, y: options.y,
width: options.width, width: options.width,
height: options.height, height: options.height,
opacity: options.opacity !== undefined ?
options.opacity : _this.opacity,
maxImageCacheCount: _this.maxImageCacheCount,
imageLoaderLimit: _this.imageLoaderLimit, imageLoaderLimit: _this.imageLoaderLimit,
minZoomImageRatio: _this.minZoomImageRatio, minZoomImageRatio: _this.minZoomImageRatio,
wrapHorizontal: _this.wrapHorizontal, wrapHorizontal: _this.wrapHorizontal,
@ -1113,7 +1110,6 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
blendTime: _this.blendTime, blendTime: _this.blendTime,
alwaysBlend: _this.alwaysBlend, alwaysBlend: _this.alwaysBlend,
minPixelRatio: _this.minPixelRatio, minPixelRatio: _this.minPixelRatio,
timeout: _this.timeout,
debugMode: _this.debugMode, debugMode: _this.debugMode,
debugGridColor: _this.debugGridColor debugGridColor: _this.debugGridColor
}); });
@ -1889,6 +1885,8 @@ function openTileSource( viewer, source, options ) {
_this.source.overlays = _this.source.overlays || []; _this.source.overlays = _this.source.overlays || [];
_this.imageLoader = new $.ImageLoader();
_this.tileCache = new $.TileCache({ _this.tileCache = new $.TileCache({
maxImageCacheCount: _this.maxImageCacheCount maxImageCacheCount: _this.maxImageCacheCount
}); });
@ -1901,19 +1899,7 @@ function openTileSource( viewer, source, options ) {
viewer: _this, viewer: _this,
viewport: _this.viewport, viewport: _this.viewport,
element: _this.canvas, element: _this.canvas,
opacity: _this.opacity, opacity: _this.opacity
imageLoaderLimit: _this.imageLoaderLimit,
minZoomImageRatio: _this.minZoomImageRatio,
wrapHorizontal: _this.wrapHorizontal,
wrapVertical: _this.wrapVertical,
immediateRender: _this.immediateRender,
blendTime: _this.blendTime,
alwaysBlend: _this.alwaysBlend,
minPixelRatio: _this.collectionMode ? 0 : _this.minPixelRatio,
timeout: _this.timeout,
debugMode: _this.debugMode,
debugGridColor: _this.debugGridColor,
crossOriginPolicy: _this.crossOriginPolicy
}); });
var tiledImage = new $.TiledImage({ var tiledImage = new $.TiledImage({
@ -1922,11 +1908,11 @@ function openTileSource( viewer, source, options ) {
viewport: _this.viewport, viewport: _this.viewport,
drawer: _this.drawer, drawer: _this.drawer,
tileCache: _this.tileCache, tileCache: _this.tileCache,
imageLoader: _this.imageLoader,
x: options.x, x: options.x,
y: options.y, y: options.y,
width: options.width, width: options.width,
height: options.height, height: options.height,
opacity: _this.opacity,
imageLoaderLimit: _this.imageLoaderLimit, imageLoaderLimit: _this.imageLoaderLimit,
minZoomImageRatio: _this.minZoomImageRatio, minZoomImageRatio: _this.minZoomImageRatio,
wrapHorizontal: _this.wrapHorizontal, wrapHorizontal: _this.wrapHorizontal,
@ -1935,7 +1921,6 @@ function openTileSource( viewer, source, options ) {
blendTime: _this.blendTime, blendTime: _this.blendTime,
alwaysBlend: _this.alwaysBlend, alwaysBlend: _this.alwaysBlend,
minPixelRatio: _this.collectionMode ? 0 : _this.minPixelRatio, minPixelRatio: _this.collectionMode ? 0 : _this.minPixelRatio,
timeout: _this.timeout,
debugMode: _this.debugMode, debugMode: _this.debugMode,
debugGridColor: _this.debugGridColor, debugGridColor: _this.debugGridColor,
crossOriginPolicy: _this.crossOriginPolicy crossOriginPolicy: _this.crossOriginPolicy

View File

@ -145,6 +145,12 @@ $.World.prototype = /** @lends OpenSeadragon.World.prototype */{
this.raiseEvent( 'remove-layer', { drawer: item } ); this.raiseEvent( 'remove-layer', { drawer: item } );
}, },
resetTiles: function() {
for (var i = 0; i < this._items.length; i++ ) {
this._items[i].reset();
}
},
update: function() { update: function() {
for (var i = 0; i < this._items.length; i++ ) { for (var i = 0; i < this._items.length; i++ ) {
this._items[i].update(); this._items[i].update();