Support removal of base layer.

This commit is contained in:
Antoine Vandecreme 2014-01-22 11:33:59 -05:00
parent 1c1cd0dc4d
commit 53ec6889e0
2 changed files with 32 additions and 17 deletions

View File

@ -1181,6 +1181,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
},
/**
* Remove a layer. If there is only one layer, close the viewer.
* @function
* @param {OpenSeadragon.Drawer} drawer The underlying drawer of the layer
* to remove
@ -1193,7 +1194,14 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
return this;
}
if ( index === 0 ) {
throw new Error( "Cannot remove base layer." );
if ( THIS[ this.hash ].sequenced ) {
throw new Error( "Cannot remove base layer when in sequence mode." );
}
if ( this.drawers.length === 1 ) {
this.close();
return this;
}
this.drawer = this.drawers[ 1 ];
}
this.drawers.splice( index, 1 );

View File

@ -162,11 +162,11 @@
var options = {
tileSource: {
type: 'legacy-image-pyramid',
levels: [ {
levels: [{
url: "data/A.png",
width: 1000,
height: 1000
} ]
}]
},
level: 0
};
@ -180,12 +180,19 @@
equal( viewer.drawer, aDrawer, "Viewer.drawer should be set to aDrawer." );
viewer.setLayerLevel( aDrawer, 1 );
equal( viewer.drawer, testPatternDrawer, "Viewer.drawer should be set back to testPatternDrawer." );
start( );
} );
viewer.removeLayer( viewer.drawer );
equal( viewer.drawer, aDrawer, "Viewer.drawer must be reassigned when removing base layer." );
viewer.removeLayer( viewer.drawer );
ok( !viewer.isOpen(), "Viewer should be closed when removing last layer." );
start();
});
viewer.addLayer( options );
} );
});
viewer.open( '/test/data/testpattern.dzi' );
} );
});
asyncTest( 'Layers and sequences', function() {
expect( 1 );
@ -209,37 +216,37 @@
// }]}] );
viewer.close();
viewer = OpenSeadragon( {
viewer = OpenSeadragon({
id: 'layersexample',
prefixUrl: '/build/openseadragon/images/',
springStiffness: 100, // Faster animation = faster tests
tileSources: [ {
tileSources: [{
type: 'legacy-image-pyramid',
levels: [ {
levels: [{
url: "data/A.png",
width: 1000,
height: 1000
} ]
}]
},
{
type: 'legacy-image-pyramid',
levels: [ {
levels: [{
url: "data/BBlue.png",
width: 1000,
height: 1000
} ] } ]
} );
}]
}]
});
// End workaround
var options = {
tileSource: {
type: 'legacy-image-pyramid',
levels: [ {
levels: [{
url: "data/CCyan.png",
width: 1000,
height: 1000
} ]
}]
}
};