From 06d263b4be3f0c0584b28f8d850585219bff36a4 Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov Date: Thu, 18 Feb 2016 01:43:53 +0300 Subject: [PATCH 1/4] Add Viewer.getOverlayById and Overlay.getBounds functions --- src/overlay.js | 8 ++++++++ src/viewer.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/overlay.js b/src/overlay.js index 41f8b9be..a2a5b1a3 100644 --- a/src/overlay.js +++ b/src/overlay.js @@ -312,6 +312,14 @@ this.placement = location instanceof $.Point ? placement : $.OverlayPlacement.TOP_LEFT; + }, + /** + * @function + * @returns {OpenSeadragon.Rect} overlay bounds + */ + getBounds: function() { + + return this.bounds; } }; diff --git a/src/viewer.js b/src/viewer.js index b1342e88..8a2e5b0a 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1944,7 +1944,28 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, this.raiseEvent( 'clear-overlay', {} ); return this; }, + + /** + * Finds an overlay identified by the reference element or element id + * and returns it as an object, return false if not found. + * @method + * @param {Element|String} element - A reference to the element or an + * element id which represent the ovelay content to be removed. + * @return {OpenSeadragon.Overlay} Chainable. + */ + getOverlayById: function( element ) { + var i; + element = $.getElement( element ); + i = getOverlayIndex( this.currentOverlays, element ); + + if (i>=0) { + return this.currentOverlays[i]; + } else { + return false; + } + + }, /** * Updates the sequence buttons. * @function OpenSeadragon.Viewer.prototype._updateSequenceButtons From 7bcb1cc59f4af9bd302df70efbeaa7437bd5f17f Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov Date: Sat, 20 Feb 2016 00:44:33 +0300 Subject: [PATCH 2/4] return clone of bounds in Overlay.getBounds so original bounds wouldn't be affected --- src/overlay.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlay.js b/src/overlay.js index a2a5b1a3..ac464c7a 100644 --- a/src/overlay.js +++ b/src/overlay.js @@ -319,7 +319,7 @@ */ getBounds: function() { - return this.bounds; + return this.bounds.clone(); } }; From 97381b04a908d41ad10415b8656c06f07bd1bdfd Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov Date: Sat, 20 Feb 2016 00:45:33 +0300 Subject: [PATCH 3/4] return null instead of false in Viewer.getOverlayById function and correct documentation --- src/viewer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 8a2e5b0a..6165b18e 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1947,11 +1947,11 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, /** * Finds an overlay identified by the reference element or element id - * and returns it as an object, return false if not found. + * and returns it as an object, return null if not found. * @method * @param {Element|String} element - A reference to the element or an * element id which represent the ovelay content to be removed. - * @return {OpenSeadragon.Overlay} Chainable. + * @return {OpenSeadragon.Overlay} the matching overlay or null if none found. */ getOverlayById: function( element ) { var i; @@ -1962,7 +1962,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, if (i>=0) { return this.currentOverlays[i]; } else { - return false; + return null; } }, From c44f134a6afb6d07c53a1dcdbfba8b5927703758 Mon Sep 17 00:00:00 2001 From: Alexey Tikhonov Date: Tue, 23 Feb 2016 02:22:47 +0300 Subject: [PATCH 4/4] remove 'to be removed' from getOverlayById @param comment to avoid confusion --- src/viewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/viewer.js b/src/viewer.js index 6165b18e..58d4b570 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1950,7 +1950,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * and returns it as an object, return null if not found. * @method * @param {Element|String} element - A reference to the element or an - * element id which represent the ovelay content to be removed. + * element id which represent the overlay content. * @return {OpenSeadragon.Overlay} the matching overlay or null if none found. */ getOverlayById: function( element ) {