diff --git a/src/viewer.js b/src/viewer.js
index 1fb5027e..64f9490e 100644
--- a/src/viewer.js
+++ b/src/viewer.js
@@ -860,6 +860,22 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
return this;
},
+ /**
+ * Turns debugging mode on or off for this viewer.
+ *
+ * @function
+ * @param {Boolean} true to turn debug on, false to turn debug off.
+ */
+ setDebugMode: function(debugMode){
+
+ for (var i = 0; i < this.world.getItemCount(); i++) {
+ this.world.getItemAt(i).debugMode = debugMode;
+ }
+
+ this.debugMode = debugMode;
+ this.forceRedraw();
+ },
+
/**
* @function
* @return {Boolean}
diff --git a/test/demo/setdebugmode.html b/test/demo/setdebugmode.html
new file mode 100644
index 00000000..838e62ca
--- /dev/null
+++ b/test/demo/setdebugmode.html
@@ -0,0 +1,44 @@
+
+
+
+
+ OpenSeadragon Basic Demo
+
+
+
+
+
+
+
+ Turn debug mode on and off after viewer has been created.
+
+
+
+
+
+
+
+
diff --git a/test/modules/basic.js b/test/modules/basic.js
index 7dc2a9ef..1e630f9b 100644
--- a/test/modules/basic.js
+++ b/test/modules/basic.js
@@ -424,6 +424,40 @@
} );
+
+ asyncTest('SetDebugMode', function() {
+ ok(viewer, 'Viewer exists');
+
+ var checkImageTilesDebugState = function (expectedState) {
+
+ for (var i = 0; i < viewer.world.getItemCount(); i++) {
+ if(viewer.world.getItemAt(i).debugMode != expectedState) {
+ return false;
+ }
+ }
+ return true;
+ };
+
+ var openHandler = function(event) {
+ viewer.removeHandler('open', openHandler);
+
+ //Ensure we start with debug mode turned off
+ viewer.setDebugMode(false);
+ ok(checkImageTilesDebugState(false), "All image tiles have debug mode turned off.");
+ ok(!viewer.debugMode, "Viewer debug mode is turned off.");
+
+ //Turn debug mode on and check that the Viewer and all tiled images are in debug mode.
+ viewer.setDebugMode(true);
+ ok(checkImageTilesDebugState(true), "All image tiles have debug mode turned on.");
+ ok(viewer.debugMode, "Viewer debug mode is turned on.");
+
+ start();
+ };
+
+ viewer.addHandler('open', openHandler);
+ viewer.open('/test/data/testpattern.dzi');
+ });
+
test('version object', function() {
equal(typeof OpenSeadragon.version.versionStr, "string", "versionStr should be a string");
ok(OpenSeadragon.version.major >= 0, "major should be a positive number");