From 9d0599983f186cba60ae07ecb04b8ec3da99c404 Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Fri, 28 Jan 2022 19:41:00 -0500 Subject: [PATCH 1/3] update version number --- openseadragon-fabricjs-overlay.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openseadragon-fabricjs-overlay.js b/openseadragon-fabricjs-overlay.js index 7ce8148..f77aed0 100755 --- a/openseadragon-fabricjs-overlay.js +++ b/openseadragon-fabricjs-overlay.js @@ -1,6 +1,6 @@ /** * OpenSeadragon canvas Overlay plugin based on svg overlay plugin and fabric.js - * @version 0.0.2 + * @version 0.6.0 */ (function () { diff --git a/package.json b/package.json index b053553..c87ec5e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openseadragon-fabricjs-overlay", - "version": "0.2.0", + "version": "0.6.0", "description": "An OpenSeadragon plugin that adds fabricjs canvas overlay capability.", "main": "openseadragon-fabricjs-overlay.js", "dependencies": { From 4981492aa3172148a43460002ddaa693a713880a Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Fri, 28 Jan 2022 19:47:38 -0500 Subject: [PATCH 2/3] Performance fix for pan and zoom Do not constantly resize canvas unless needed. --- openseadragon-fabricjs-overlay.js | 34 +++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/openseadragon-fabricjs-overlay.js b/openseadragon-fabricjs-overlay.js index f77aed0..19e1651 100755 --- a/openseadragon-fabricjs-overlay.js +++ b/openseadragon-fabricjs-overlay.js @@ -109,26 +109,20 @@ }); /** - * Update viewport + * Update Pan & Zoom accordingly on viewport-change */ - this._viewer.addHandler('update-viewport', function () { - self.resize(); - self.resizeCanvas(); - self.render(); - - }); + this._viewer.addHandler('viewport-change', self.OnViewportChange.bind(self)); /** * Resize the fabric.js overlay when the viewer or window changes size */ - this._viewer.addHandler('open', function () { - self.resize(); - self.resizeCanvas(); - }); - window.addEventListener('resize', function () { + let doResizeAll = function (){ self.resize(); self.resizeCanvas(); - }); + }; + this._viewer.addHandler('open', doResizeAll); + this._viewer.addHandler('resize', doResizeAll); + window.addEventListener('resize', doResizeAll); }; @@ -189,6 +183,20 @@ this._fabricCanvas.absolutePan(new fabric.Point(canvasOffset.left - x + pageScroll.x, canvasOffset.top - y + pageScroll.y)); + }, + OnViewportChange: function(e) { + // update view bounds this way to avoid reszing the canvas, since it's expensive to constantly resize the canvas... + + // get Zoom + let cSize = this._viewer.viewport._containerInnerSize; + let zoom = cSize.x * this._viewer.viewport.getZoom(true) / this._scale; + + // get X,Y position + let b = this._viewer.viewport.getBounds(true); + let wPt = this._viewer.viewport.pixelFromPoint(new OpenSeadragon.Point(b), true); + + // update the canvas viewport + this._fabricCanvas.setViewportTransform([zoom, 0, 0, zoom, wPt.x, wPt.y]); } }; From 7d55f4007345071a866cc5c05dad890d726f7747 Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Fri, 28 Jan 2022 19:56:28 -0500 Subject: [PATCH 3/3] update comments --- openseadragon-fabricjs-overlay.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openseadragon-fabricjs-overlay.js b/openseadragon-fabricjs-overlay.js index 19e1651..76f8c5e 100755 --- a/openseadragon-fabricjs-overlay.js +++ b/openseadragon-fabricjs-overlay.js @@ -185,7 +185,8 @@ }, OnViewportChange: function(e) { - // update view bounds this way to avoid reszing the canvas, since it's expensive to constantly resize the canvas... + // Update view bounds this way to avoid reszing the canvas, since it's expensive to constantly resize the canvas... + // Currently no support for rotation since fabric does not support viewport rotation... // get Zoom let cSize = this._viewer.viewport._containerInnerSize;