mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-21 20:56:09 +03:00
consolidate tiled-image-drawn event description and firing code
This commit is contained in:
parent
8be2ca2dfb
commit
500c22feb1
@ -479,24 +479,9 @@ class CanvasDrawer extends $.DrawerBase{
|
|||||||
this._drawDebugInfo( tiledImage, lastDrawn );
|
this._drawDebugInfo( tiledImage, lastDrawn );
|
||||||
|
|
||||||
// Fire tiled-image-drawn event.
|
// Fire tiled-image-drawn event.
|
||||||
if( this.viewer ){
|
|
||||||
/**
|
this._raiseTiledImageDrawnEvent(tiledImage, lastDrawn);
|
||||||
* 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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -252,6 +252,33 @@ $.DrawerBase = class DrawerBase{
|
|||||||
return new OpenSeadragon.Point( Math.round(viewportSize.x * pixelDensityRatio), Math.round(viewportSize.y * pixelDensityRatio));
|
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 ));
|
}( OpenSeadragon ));
|
||||||
|
@ -352,25 +352,7 @@
|
|||||||
gl.clear(gl.COLOR_BUFFER_BIT); // clear the back buffer
|
gl.clear(gl.COLOR_BUFFER_BIT); // clear the back buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire tiled-image-drawn event. This is used for the tests
|
this._raiseTiledImageDrawnEvent(tiledImage, tilesToDraw.map(info=>info.tile));
|
||||||
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),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
viewer = OpenSeadragon({
|
viewer = OpenSeadragon({
|
||||||
id: 'example',
|
id: 'example',
|
||||||
prefixUrl: '/build/openseadragon/images/',
|
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() {
|
afterEach: function() {
|
||||||
@ -132,8 +133,7 @@
|
|||||||
QUnit.test('update', function(assert) {
|
QUnit.test('update', function(assert) {
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
var handlerCount = 0;
|
var handlerCount = 0;
|
||||||
var testTileDrawingEvent = viewer.drawer.getType() === 'canvas';
|
let expectedHandlers = 4;
|
||||||
let expectedHandlers = testTileDrawingEvent ? 4 : 3;
|
|
||||||
|
|
||||||
viewer.addHandler('open', function(event) {
|
viewer.addHandler('open', function(event) {
|
||||||
var image = viewer.world.getItemAt(0);
|
var image = viewer.world.getItemAt(0);
|
||||||
@ -162,17 +162,17 @@
|
|||||||
assert.ok(event.tile, 'update-tile event includes tile');
|
assert.ok(event.tile, 'update-tile event includes tile');
|
||||||
});
|
});
|
||||||
|
|
||||||
if(testTileDrawingEvent){
|
|
||||||
viewer.addHandler('tile-drawing', function tileDrawingHandler(event) {
|
viewer.addHandler('tile-drawing', function tileDrawingHandler(event) {
|
||||||
viewer.removeHandler('tile-drawing', tileDrawingHandler);
|
viewer.removeHandler('tile-drawing', tileDrawingHandler);
|
||||||
handlerCount++;
|
handlerCount++;
|
||||||
assert.equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer');
|
assert.equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer');
|
||||||
assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct');
|
assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct');
|
||||||
assert.ok(event.tile, 'tile-drawing event includes a tile');
|
assert.ok(event.tile, 'tile-drawing event includes a tile');
|
||||||
assert.ok(event.context, 'tile-drawing event includes a context');
|
assert.ok(event.context, 'tile-drawing event includes a context');
|
||||||
assert.ok(event.rendered, 'tile-drawing event includes a rendered');
|
assert.ok(event.rendered, 'tile-drawing event includes a rendered');
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
viewer.addHandler('tiled-image-drawn', function tileDrawnHandler(event) {
|
viewer.addHandler('tiled-image-drawn', function tileDrawnHandler(event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user