Prevent adding collections as layers.

This commit is contained in:
Antoine Vandecreme 2014-01-11 19:15:28 -05:00
parent f0f76b847e
commit cd62ba7eca
2 changed files with 63 additions and 14 deletions

View File

@ -1012,7 +1012,32 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
throw new Error( "No tile source provided as new layer." ); throw new Error( "No tile source provided as new layer." );
} }
function raiseAddLayerFailed( event ) {
/**
* Raised when an error occurs while adding a layer.
* @event add-layer-failed
* @memberOf OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {String} message
* @property {String} source
* @property {Object} options The options passed to the addLayer method.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
_this.raiseEvent( 'add-layer-failed', event );
}
getTileSourceImplementation( this, tileSource, function( tileSource ) { getTileSourceImplementation( this, tileSource, function( tileSource ) {
if ( tileSource instanceof Array ) {
raiseAddLayerFailed({
message: "Collections can not be added as layers.",
source: tileSource,
options: options
});
return;
}
var drawer = new $.Drawer({ var drawer = new $.Drawer({
viewer: _this, viewer: _this,
source: tileSource, source: tileSource,
@ -1054,18 +1079,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
}); });
}, function( event ) { }, function( event ) {
event.options = options; event.options = options;
/** raiseAddLayerFailed(event);
* Raised when an error occurs while adding a layer.
* @event add-layer-failed
* @memberOf OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised the event.
* @property {String} message
* @property {String} source
* @property {Object} options The options passed to the addLayer method.
* @property {?Object} userData - Arbitrary subscriber-defined object.
*/
_this.raiseEvent( 'add-layer-failed', event );
} ); } );
return this; return this;

View File

@ -37,7 +37,7 @@
tileSource: { tileSource: {
type: 'legacy-image-pyramid', type: 'legacy-image-pyramid',
levels: [ { levels: [ {
url: "test/data/A.png", url: "data/A.png",
width: 1000, width: 1000,
height: 1000 height: 1000
} ] } ]
@ -89,7 +89,7 @@
"The layer at level 2 should be layer1." ); "The layer at level 2 should be layer1." );
options.level = 2; options.level = 2;
options.tileSource.levels[0].url = "test/data/CCyan.png"; options.tileSource.levels[0].url = "data/CCyan.png";
options.opacity = 0.5; options.opacity = 0.5;
viewer.addLayer( options ); viewer.addLayer( options );
viewer.addHandler( "add-layer", function addThirdLayerHandler( event ) { viewer.addHandler( "add-layer", function addThirdLayerHandler( event ) {
@ -125,5 +125,40 @@
viewer.open( '/test/data/testpattern.dzi' ); viewer.open( '/test/data/testpattern.dzi' );
}); });
asyncTest( 'Collections as layers', function() {
var options = {
tileSource: [{
type: 'legacy-image-pyramid',
levels: [{
url: "data/A.png",
width: 1000,
height: 1000
}]
}, {
type: 'legacy-image-pyramid',
levels: [{
url: "data/BBlue.png",
width: 1000,
height: 1000
}]
}]
};
viewer.addHandler( "open", function openHandler() {
viewer.removeHandler( "open", openHandler );
viewer.addHandler( "add-layer-failed",
function addLayerFailedHandler( event ) {
viewer.removeHandler( "add-layer-failed", addLayerFailedHandler );
equal( event.message, "Collections can not be added as layers." );
equal( event.options, options, "Layer failed event should give the options." );
start();
} );
viewer.addLayer( options );
});
viewer.open( '/test/data/testpattern.dzi' );
});
})(); })();