This repository was archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCanvasViewer.tsx
60 lines (58 loc) · 2.23 KB
/
CanvasViewer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { FC } from 'react';
import { TileSet } from '@atlas-viewer/atlas';
import { useCanvas, useResourceEvents, useRenderingStrategy, useThumbnail } from '@hyperion-framework/react-vault';
import { RenderAnnotationPage } from '../RenderAnnotationPage/RenderAnnotationPage';
export const CanvasViewer: FC<{ x?: number; y?: number }> = ({ x, y }) => {
const canvas = useCanvas();
const elementProps = useResourceEvents(canvas, 'deep-zoom');
const [strategy] = useRenderingStrategy({
strategies: ['images'],
});
const thumbnail = useThumbnail({ maxWidth: 256, maxHeight: 256 });
return (
<world-object height={canvas.height} width={canvas.width} x={x} y={y} {...elementProps}>
{strategy.type === 'images'
? strategy.images.map((image, idx) => {
return (
<React.Fragment key={image.id}>
{!image.service ? (
<world-image
uri={image.id}
target={image.target}
display={
image.width && image.height
? {
width: image.width,
height: image.height,
}
: undefined
}
/>
) : (
<TileSet
key={image.service.id}
tiles={{
id: image.service.id,
height: image.height,
width: image.width,
imageService: image.service as any,
thumbnail: idx === 0 && thumbnail && thumbnail.type === 'fixed' ? thumbnail : undefined,
}}
x={image.target?.x}
y={image.target?.y}
width={image.target?.width}
height={image.target?.height}
/>
)}
</React.Fragment>
);
})
: null}
{strategy.annotations && strategy.annotations.pages
? strategy.annotations.pages.map(page => {
return <RenderAnnotationPage key={page.id} page={page} />;
})
: null}
</world-object>
);
};