Skip to content

Commit

Permalink
have viewer update with xywh coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoneill committed Dec 10, 2024
1 parent 26409c7 commit d3b75b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions __tests__/src/components/OpenSeadragonViewer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('OpenSeadragonViewer', () => {
getBounds: () => [],
getFlip: () => false,
getRotation: () => 90,
viewportToImageRectangle: () => '0,0,0,0',
zoomSpring: { target: { value: 0.5 } },
});

Expand Down
10 changes: 10 additions & 0 deletions src/components/OpenSeadragonComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ function OpenSeadragonComponent({
viewerRef.current?.raiseEvent('mouse-move', event);
}, [viewerRef]), 10);

/** OSD returns negative and float bounds */
const convertToIIIFCoords = (bounds) => {
if (bounds < 0) return 0;
return Math.round(bounds);
};

const onViewportChange = useCallback((event) => {
const { viewport } = event.eventSource;

const imageBounds = viewport.viewportToImageRectangle(viewport.getBounds());
const parsedBounds = `${convertToIIIFCoords(imageBounds.x)},${convertToIIIFCoords(imageBounds.y)},${convertToIIIFCoords(imageBounds.width)},${convertToIIIFCoords(imageBounds.height)}`;
viewerRef.current?.element.parentNode.setAttribute('data-xywh-coords', parsedBounds);

onUpdateViewport({
bounds: viewport.getBounds(),
flip: viewport.getFlip(),
Expand Down
2 changes: 1 addition & 1 deletion src/components/PrimaryWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function PrimaryWindow({
};

return (
<Root data-testid="test-window" className={classNames(ns('primary-window'), className)}>
<Root data-testid="test-window" data-parent-window-id={windowId} className={classNames(ns('primary-window'), className)}>
<WindowSideBar windowId={windowId} />
<CompanionArea windowId={windowId} position="left" />
{ isCollectionDialogVisible && <CollectionDialog windowId={windowId} /> }
Expand Down

0 comments on commit d3b75b5

Please sign in to comment.