consolidate tiled-image-drawn event description and firing code

This commit is contained in:
Tom 2024-01-10 18:00:01 -05:00
parent 8be2ca2dfb
commit 500c22feb1
4 changed files with 45 additions and 51 deletions

View File

@ -479,24 +479,9 @@ class CanvasDrawer extends $.DrawerBase{
this._drawDebugInfo( tiledImage, lastDrawn );
// Fire tiled-image-drawn event.
if( this.viewer ){
/**
* Raised when a tiled image is drawn to the canvas. Used internally for testing.
* The update-viewport event is preferred if you want to know when a frame has been drawn.
*
* @event tiled-image-drawn
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn.
* @property {Array} tiles - An array of Tile objects that were drawn.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent( 'tiled-image-drawn', {
tiledImage: tiledImage,
tiles: lastDrawn,
});
}
this._raiseTiledImageDrawnEvent(tiledImage, lastDrawn);
}
/**

View File

@ -252,6 +252,33 @@ $.DrawerBase = class DrawerBase{
return new OpenSeadragon.Point( Math.round(viewportSize.x * pixelDensityRatio), Math.round(viewportSize.y * pixelDensityRatio));
}
/**
* Called by implementations to fire the tiled-image-drawn event (used by tests)
* @private
*/
_raiseTiledImageDrawnEvent(tiledImage, tiles){
if(!this.viewer) {
return;
}
/**
* Raised when a tiled image is drawn to the canvas. Used internally for testing.
* The update-viewport event is preferred if you want to know when a frame has been drawn.
*
* @event tiled-image-drawn
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn.
* @property {Array} tiles - An array of Tile objects that were drawn.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent( 'tiled-image-drawn', {
tiledImage: tiledImage,
tiles: tiles,
});
}
};
}( OpenSeadragon ));

View File

@ -352,25 +352,7 @@
gl.clear(gl.COLOR_BUFFER_BIT); // clear the back buffer
}
// Fire tiled-image-drawn event. This is used for the tests
if( this.viewer ){
/**
* Raised when a tiled image is drawn to the canvas. Used internally for testing.
* The update-viewport event is preferred if you want to know when a frame has been drawn.
*
* @event tiled-image-drawn
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {OpenSeadragon.TiledImage} tiledImage - Which TiledImage is being drawn.
* @property {Array} tiles - An array of Tile objects that were drawn.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
this.viewer.raiseEvent( 'tiled-image-drawn', {
tiledImage: tiledImage,
tiles: tilesToDraw.map(info => info.tile),
});
}
this._raiseTiledImageDrawnEvent(tiledImage, tilesToDraw.map(info=>info.tile));
});

View File

@ -13,7 +13,8 @@
viewer = OpenSeadragon({
id: 'example',
prefixUrl: '/build/openseadragon/images/',
springStiffness: 100 // Faster animation = faster tests
springStiffness: 100, // Faster animation = faster tests
drawer: 'canvas', // always use canvas drawer for these tests
});
},
afterEach: function() {
@ -132,8 +133,7 @@
QUnit.test('update', function(assert) {
var done = assert.async();
var handlerCount = 0;
var testTileDrawingEvent = viewer.drawer.getType() === 'canvas';
let expectedHandlers = testTileDrawingEvent ? 4 : 3;
let expectedHandlers = 4;
viewer.addHandler('open', function(event) {
var image = viewer.world.getItemAt(0);
@ -162,7 +162,7 @@
assert.ok(event.tile, 'update-tile event includes tile');
});
if(testTileDrawingEvent){
viewer.addHandler('tile-drawing', function tileDrawingHandler(event) {
viewer.removeHandler('tile-drawing', tileDrawingHandler);
handlerCount++;
@ -172,7 +172,7 @@
assert.ok(event.context, 'tile-drawing event includes a context');
assert.ok(event.rendered, 'tile-drawing event includes a rendered');
});
}
viewer.addHandler('tiled-image-drawn', function tileDrawnHandler(event) {