mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 14:46:10 +03:00
Merge pull request #2059 from kim-sanghoon/fix/getLevelScale
Fix getLevelScale to use image dimensions
This commit is contained in:
commit
1454ac791a
@ -284,10 +284,14 @@ $.TileSource.prototype = {
|
|||||||
// see https://github.com/openseadragon/openseadragon/issues/22
|
// see https://github.com/openseadragon/openseadragon/issues/22
|
||||||
// we use the tilesources implementation of getLevelScale to generate
|
// we use the tilesources implementation of getLevelScale to generate
|
||||||
// a memoized re-implementation
|
// a memoized re-implementation
|
||||||
var levelScaleCache = {},
|
var maxLevel = Math.ceil(
|
||||||
|
Math.log( Math.max( this.dimensions.x, this.dimensions.y ) ) /
|
||||||
|
Math.log( 2 )
|
||||||
|
),
|
||||||
|
levelScaleCache = {},
|
||||||
i;
|
i;
|
||||||
for( i = 0; i <= this.maxLevel; i++ ){
|
for( i = 0; i <= maxLevel; i++ ){
|
||||||
levelScaleCache[ i ] = 1 / Math.pow(2, this.maxLevel - i);
|
levelScaleCache[ i ] = 1 / Math.pow(2, maxLevel - i);
|
||||||
}
|
}
|
||||||
this.getLevelScale = function( _level ){
|
this.getLevelScale = function( _level ){
|
||||||
return levelScaleCache[ _level ];
|
return levelScaleCache[ _level ];
|
||||||
|
@ -120,4 +120,27 @@
|
|||||||
assertTileAtPoint(0, new OpenSeadragon.Point(1, 3033 / 2000), new OpenSeadragon.Point(0, 0));
|
assertTileAtPoint(0, new OpenSeadragon.Point(1, 3033 / 2000), new OpenSeadragon.Point(0, 0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('changing maxLevel', function(assert) {
|
||||||
|
var tileSource = new OpenSeadragon.TileSource({
|
||||||
|
width: 4096,
|
||||||
|
height: 4096,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(tileSource.maxLevel, 12, 'The initial max level should be 12.');
|
||||||
|
|
||||||
|
tileSource.maxLevel = 9;
|
||||||
|
|
||||||
|
function assertLevelScale(level, expected) {
|
||||||
|
var actual = tileSource.getLevelScale(level);
|
||||||
|
assert.ok(Math.abs(actual - expected) < Number.EPSILON, "The scale at level " + level +
|
||||||
|
" should be " + expected.toString() +
|
||||||
|
" got " + actual.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertLevelScale(12, 1);
|
||||||
|
assertLevelScale(10, 1 / 4);
|
||||||
|
assertLevelScale(8, 1 / 16);
|
||||||
|
assertLevelScale(6, 1 / 64);
|
||||||
|
});
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
Loading…
Reference in New Issue
Block a user