Skip to content

Commit

Permalink
Address new OSD instantiation drift.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewjordan committed Dec 12, 2023
1 parent 79deda5 commit adfc454
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/components/Viewer/ImageViewer/OSD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ interface OSDProps {

const OSD: React.FC<OSDProps> = ({ uri, hasPlaceholder, imageType }) => {
const [osdUri, setOsdUri] = useState<string>();
const [osdInstance, setOsdInstance] = useState<string>();
const viewerState: ViewerContextStore = useViewerState();
const { configOptions } = viewerState;

const instance = uuidv4();

const config: Options = {
id: `openseadragon-viewport-${instance}`,
id: `openseadragon-viewport-${osdInstance}`,
loadTilesWithAjax: true,
fullPageButton: "fullPage",
homeButton: "reset",
Expand All @@ -41,7 +40,7 @@ const OSD: React.FC<OSDProps> = ({ uri, hasPlaceholder, imageType }) => {
showRotationControl: true,
showZoomControl: true,
navigatorBorderColor: "transparent",
navigatorId: `openseadragon-navigator-${instance}`,
navigatorId: `openseadragon-navigator-${osdInstance}`,
gestureSettingsMouse: {
clickToZoom: true,
dblClickToZoom: true,
Expand All @@ -53,7 +52,10 @@ const OSD: React.FC<OSDProps> = ({ uri, hasPlaceholder, imageType }) => {
};

useEffect(() => {
if (uri !== osdUri) setOsdUri(uri);
if (uri !== osdUri) {
setOsdUri(uri);
setOsdInstance(uuidv4());
}
}, [osdUri, uri]);

useEffect(() => {
Expand All @@ -80,6 +82,8 @@ const OSD: React.FC<OSDProps> = ({ uri, hasPlaceholder, imageType }) => {
}
}, [osdUri]);

if (!osdInstance) return null;

return (
<Wrapper
css={{
Expand All @@ -88,8 +92,8 @@ const OSD: React.FC<OSDProps> = ({ uri, hasPlaceholder, imageType }) => {
}}
>
<Controls hasPlaceholder={hasPlaceholder} options={config} />
<Navigator id={`openseadragon-navigator-${instance}`} />
<Viewport id={`openseadragon-viewport-${instance}`} />
<Navigator id={`openseadragon-navigator-${osdInstance}`} />
<Viewport id={`openseadragon-viewport-${osdInstance}`} />
</Wrapper>
);
};
Expand Down

0 comments on commit adfc454

Please sign in to comment.