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( $ ){
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
* @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
//idiomatic javascript options object as the only argument
var args = arguments,
i;
var args = arguments;
if( !$.isPlainObject( 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 ) {
$.console.error( "[Drawer] options.source is no longer accepted; use TiledImage instead" );
}
$.extend( true, this, {
//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.viewer = options.viewer;
this.opacity = options.opacity === undefined ? $.DEFAULT_SETTINGS.opacity : options.opacity;
this.useCanvas = $.supportsCanvas && ( this.viewer ? this.viewer.useCanvas : true );
/**
@ -118,7 +77,7 @@ $.Drawer = function( options ) {
* @member {Element} container
* @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.
* Child element of {@link OpenSeadragon.Drawer#container}.
@ -269,6 +228,7 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
getOpacity: function() {
return this.opacity;
},
/**
* Returns whether the Drawer is scheduled for an update at the
* soonest possible opportunity.
@ -277,7 +237,8 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* soonest possible opportunity.
*/
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.
*/
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.
*/
reset: function() {
this.lastResetTime = $.now();
this.updateAgain = true;
$.console.error( "[Drawer.reset] this function is deprecated." );
return this;
},
@ -308,10 +269,7 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* @return {OpenSeadragon.Drawer} Chainable.
*/
update: function() {
//this.profiler.beginUpdate();
this.midUpdate = true;
this.midUpdate = false;
//this.profiler.endUpdate();
$.console.error( "[Drawer.update] this function is deprecated." );
return this;
},
@ -330,11 +288,6 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
* @return null
*/
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)
this.canvas.width = 1;
this.canvas.height = 1;

View File

@ -44,6 +44,8 @@
$.TiledImage = function( options ) {
$.console.assert( options.tileCache, "[TiledImage] options.tileCache 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;
delete options.tileCache;
@ -51,6 +53,9 @@ $.TiledImage = function( options ) {
this._drawer = options.drawer;
delete options.drawer;
this._imageLoader = options.imageLoader;
delete options.imageLoader;
this._worldX = options.x || 0;
delete options.x;
this._worldY = options.y || 0;
@ -81,7 +86,6 @@ $.TiledImage = function( options ) {
//internal state properties
viewer: null,
imageLoader: new $.ImageLoader(),
tilesMatrix: {}, // A '3d' dictionary [level][x][y] --> Tile.
coverage: {}, // A '3d' dictionary [level][x][y] --> Boolean.
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?
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
opacity: $.DEFAULT_SETTINGS.opacity,
maxImageCacheCount: $.DEFAULT_SETTINGS.maxImageCacheCount,
minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio,
wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal,
wrapVertical: $.DEFAULT_SETTINGS.wrapVertical,
@ -104,34 +102,12 @@ $.TiledImage = function( options ) {
alwaysBlend: $.DEFAULT_SETTINGS.alwaysBlend,
minPixelRatio: $.DEFAULT_SETTINGS.minPixelRatio,
debugMode: $.DEFAULT_SETTINGS.debugMode,
timeout: $.DEFAULT_SETTINGS.timeout,
crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy
}, options );
};
$.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
* soonest possible opportunity.
@ -558,7 +534,7 @@ function getTile( x, y, level, tileSource, tilesMatrix, time, numTiles, worldWid
function loadTile( tiledImage, tile, time ) {
tile.loading = true;
tiledImage.imageLoader.addJob({
tiledImage._imageLoader.addJob({
src: tile.url,
crossOriginPolicy: tiledImage.crossOriginPolicy,
callback: function( image ){

View File

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

View File

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