Merge pull request #2049 from superbland/get_relative_image_size

Add method for getting the relative size of an image
This commit is contained in:
Ian Gilman 2021-11-05 11:50:50 -07:00 committed by GitHub
commit f0d5d4bedd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -419,6 +419,15 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
return new $.Point(this.source.dimensions.x, this.source.dimensions.y); return new $.Point(this.source.dimensions.x, this.source.dimensions.y);
}, },
/**
* @returns {OpenSeadragon.Point} The TiledImage's content size, in window coordinates.
*/
getSizeInWindowCoordinates: function() {
var topLeft = this.imageToWindowCoordinates(new $.Point(0, 0));
var bottomRight = this.imageToWindowCoordinates(this.getContentSize());
return new $.Point(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
},
// private // private
_viewportToImageDelta: function( viewerX, viewerY, current ) { _viewportToImageDelta: function( viewerX, viewerY, current ) {
var scale = (current ? this._scaleSpring.current.value : this._scaleSpring.target.value); var scale = (current ? this._scaleSpring.current.value : this._scaleSpring.target.value);

View File

@ -41,8 +41,11 @@
viewer.addHandler('open', function(event) { viewer.addHandler('open', function(event) {
var image = viewer.world.getItemAt(0); var image = viewer.world.getItemAt(0);
var contentSize = image.getContentSize(); var contentSize = image.getContentSize();
var sizeInWindowCoords = image.getSizeInWindowCoordinates();
assert.equal(contentSize.x, 500, 'contentSize.x'); assert.equal(contentSize.x, 500, 'contentSize.x');
assert.equal(contentSize.y, 2000, 'contentSize.y'); assert.equal(contentSize.y, 2000, 'contentSize.y');
assert.equal(sizeInWindowCoords.x, 125, 'sizeInWindowCoords.x');
assert.equal(sizeInWindowCoords.y, 500, 'sizeInWindowCoords.y');
checkBounds(assert, image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds'); checkBounds(assert, image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds');
@ -74,7 +77,18 @@
image.setHeight(4); image.setHeight(4);
checkBounds(assert, image, new OpenSeadragon.Rect(7, 8, 1, 4), 'bounds after width'); checkBounds(assert, image, new OpenSeadragon.Rect(7, 8, 1, 4), 'bounds after width');
assert.equal(handlerCount, 1, 'correct number of handlers called'); viewer.addHandler('zoom', function zoomHandler(event) {
var sizeInWindowCoords = image.getSizeInWindowCoordinates();
viewer.removeHandler('zoom', zoomHandler);
handlerCount++;
assert.equal(sizeInWindowCoords.x, 4000, 'sizeInWindowCoords.x after zoom');
assert.equal(sizeInWindowCoords.y, 16000, 'sizeInWindowCoords.y after zoom');
});
viewer.viewport.zoomTo(8, null, true);
assert.equal(handlerCount, 2, 'correct number of handlers called');
done(); done();
}); });