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

@ -180,6 +180,13 @@
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." );
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 );
@ -227,8 +234,8 @@
url: "data/BBlue.png",
width: 1000,
height: 1000
} ] } ]
}]
}]
});
// End workaround