From b5bb1f87384354a8afd04b078034a74bb7e993c7 Mon Sep 17 00:00:00 2001 From: Johannes Baiter <johannes.baiter@bsb-muenchen.de> Date: Fri, 19 Nov 2021 15:50:18 +0100 Subject: [PATCH] Fix annotation rendering when OSD has viewport margin. When users configure a viewport margin for OSD (via `osdConfig.viewportMargins`), annotation rendering would be broken, since the `osd.viewport.getBoundsNoRottate()` call to get the viewport boundary would return the viewport *without* the margin, which would lead to wrong calculations down the line. The fix is to simply call `osd.viewport.getBoundsNoRotateWithMargins` instead to obtain the correct full viewport size. --- __tests__/src/lib/OpenSeadragonCanvasOverlay.test.js | 4 ++-- src/lib/OpenSeadragonCanvasOverlay.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/src/lib/OpenSeadragonCanvasOverlay.test.js b/__tests__/src/lib/OpenSeadragonCanvasOverlay.test.js index 23a785b56..22a661e72 100644 --- a/__tests__/src/lib/OpenSeadragonCanvasOverlay.test.js +++ b/__tests__/src/lib/OpenSeadragonCanvasOverlay.test.js @@ -17,7 +17,7 @@ describe('OpenSeadragonCanvasOverlay', () => { clientWidth: 200, }, viewport: { - getBoundsNoRotate: jest.fn(() => ({ + getBoundsNoRotateWithMargins: jest.fn(() => ({ height: 300, width: 200, x: 40, @@ -92,7 +92,7 @@ describe('OpenSeadragonCanvasOverlay', () => { clientWidth: 200, }, viewport: { - getBoundsNoRotate: jest.fn(() => (new OpenSeadragon.Rect(0, 0, 200, 200))), + getBoundsNoRotateWithMargins: jest.fn(() => (new OpenSeadragon.Rect(0, 0, 200, 200))), }, world: { getItemAt: jest.fn(), diff --git a/src/lib/OpenSeadragonCanvasOverlay.js b/src/lib/OpenSeadragonCanvasOverlay.js index d10bd5014..fd69cf31c 100644 --- a/src/lib/OpenSeadragonCanvasOverlay.js +++ b/src/lib/OpenSeadragonCanvasOverlay.js @@ -58,7 +58,7 @@ export default class OpenSeadragonCanvasOverlay { } this.viewportOrigin = new OpenSeadragon.Point(0, 0); - const boundsRect = this.viewer.viewport.getBoundsNoRotate(true); + const boundsRect = this.viewer.viewport.getBoundsNoRotateWithMargins(true); this.viewportOrigin.x = boundsRect.x; this.viewportOrigin.y = boundsRect.y * this.imgAspectRatio; -- GitLab