diff --git a/src/openseadragon.js b/src/openseadragon.js index 9ad73a17..4e85c905 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -193,6 +193,9 @@ * @property {Number} [opacity=1] * Opacity of the drawer (1=opaque, 0=transparent) * + * @property {Number} [layersAspectRatioEpsilon=0.0001] + * Maximum aspectRatio mismatch between 2 layers. + * * @property {Number} [degrees=0] * Initial rotation. * @@ -721,6 +724,9 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ // APPEARANCE opacity: 1, + // LAYERS SETTINGS + layersAspectRatioEpsilon: 0.0001, + //REFERENCE STRIP SETTINGS showReferenceStrip: false, referenceStripScroll: 'horizontal', diff --git a/src/viewer.js b/src/viewer.js index fcd54dc1..bd5ff377 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1044,6 +1044,19 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, 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({ viewer: _this, source: tileSource, diff --git a/test/layers.js b/test/layers.js index 78606303..a20c92d0 100644 --- a/test/layers.js +++ b/test/layers.js @@ -27,7 +27,7 @@ // ---------- asyncTest( 'Layers operations', function() { - expect( 22 ); + expect( 23 ); viewer.addHandler( "open", function( ) { equal( 1, viewer.getLayersCount( ), "One layer should be present after opening." ); @@ -112,7 +112,16 @@ }); viewer.removeLayer( layer2 ); - start(); + + 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(); + }); + viewer.addLayer( options ); }); }); });