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 4aac0dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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 4aac0dd

Please sign in to comment.