Skip to content

Commit

Permalink
Fixes a regression bug in anno.getSelectedImageSnippet
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Apr 30, 2022
1 parent 6f1ddbf commit a34aec6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/util/ImageSnippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ export const getSnippet = (viewer, element) => {
// child (in case of editable shapes, the element would be
// the group with shape + handles)
const shape = hasClass(element, '.a9s-annotation') ?
element : element.querySelector('.a9s-annotation');
element : element.closest('.a9s-annotation');

const outer = shape.querySelector('.a9s-inner');
const outerBounds = outer.getBoundingClientRect();

// Scale factor for OSD canvas element (physical vs. logical resolution)
const { canvas } = viewer.drawer;
const canvasBounds = canvas.getBoundingClientRect();
const kx = canvas.width / canvasBounds.width;
const ky = canvas.height / canvasBounds.height;

const shapeBounds = shape.getBoundingClientRect();

const x = shapeBounds.x - canvasBounds.x;
const y = shapeBounds.y - canvasBounds.y;
const { width, height } = shapeBounds;
const x = outerBounds.x - canvasBounds.x;
const y = outerBounds.y - canvasBounds.y;
const { width, height } = outerBounds;

// Cut out the image snippet as in-memory canvas element
const snippet = document.createElement('CANVAS');
Expand All @@ -27,7 +28,7 @@ export const getSnippet = (viewer, element) => {
ctx.drawImage(canvas, x * kx, y * ky, width * kx, height * ky, 0, 0, width, height);

// Compute reverse transform
const topLeft = viewer.viewport.viewportToImageCoordinates(shapeBounds.x, shapeBounds.y);
const topLeft = viewer.viewport.viewerElementToImageCoordinates(new OpenSeadragon.Point(x, y));
const imageZoom = viewer.viewport.viewportToImageZoom(viewer.viewport.getZoom());

return {
Expand Down

0 comments on commit a34aec6

Please sign in to comment.