Add layersAspectRatioEpsilon check

This commit is contained in:
Antoine Vandecreme 2014-01-30 16:43:35 -05:00
parent 53ec6889e0
commit d43b6d86b5
3 changed files with 30 additions and 2 deletions

View File

@ -193,6 +193,9 @@
* @property {Number} [opacity=1] * @property {Number} [opacity=1]
* Opacity of the drawer (1=opaque, 0=transparent) * Opacity of the drawer (1=opaque, 0=transparent)
* *
* @property {Number} [layersAspectRatioEpsilon=0.0001]
* Maximum aspectRatio mismatch between 2 layers.
*
* @property {Number} [degrees=0] * @property {Number} [degrees=0]
* Initial rotation. * Initial rotation.
* *
@ -721,6 +724,9 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
// APPEARANCE // APPEARANCE
opacity: 1, opacity: 1,
// LAYERS SETTINGS
layersAspectRatioEpsilon: 0.0001,
//REFERENCE STRIP SETTINGS //REFERENCE STRIP SETTINGS
showReferenceStrip: false, showReferenceStrip: false,
referenceStripScroll: 'horizontal', referenceStripScroll: 'horizontal',

View File

@ -1044,6 +1044,19 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
return; return;
} }
for ( var i = 0; i < _this.drawers.length; i++ ) {
var otherAspectRatio = _this.drawers[ i ].source.aspectRatio;
var diff = otherAspectRatio - tileSource.aspectRatio;
if ( Math.abs( diff ) > _this.layersAspectRatioEpsilon ) {
raiseAddLayerFailed({
message: "Aspect ratio mismatch with layer " + i + ".",
source: tileSource,
options: options
});
return;
}
}
var drawer = new $.Drawer({ var drawer = new $.Drawer({
viewer: _this, viewer: _this,
source: tileSource, source: tileSource,

View File

@ -27,7 +27,7 @@
// ---------- // ----------
asyncTest( 'Layers operations', function() { asyncTest( 'Layers operations', function() {
expect( 22 ); expect( 23 );
viewer.addHandler( "open", function( ) { viewer.addHandler( "open", function( ) {
equal( 1, viewer.getLayersCount( ), equal( 1, viewer.getLayersCount( ),
"One layer should be present after opening." ); "One layer should be present after opening." );
@ -112,8 +112,17 @@
}); });
viewer.removeLayer( layer2 ); viewer.removeLayer( layer2 );
options.tileSource.levels[0].width = 500;
viewer.addHandler( "add-layer-failed", function addLayerFailed( event ) {
viewer.removeHandler( "add-layer-failed", addLayerFailed );
equal( viewer.getLayersCount(), 3 );
start(); start();
}); });
viewer.addLayer( options );
});
}); });
}); });
}); });