Skip to content
Snippets Groups Projects
Commit bfedb5b8 authored by Jack Reed's avatar Jack Reed
Browse files

Breakout WebAnnotation model

parent 930e6211
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,10 @@ const config = { ...@@ -9,6 +9,10 @@ const config = {
adapter: (canvasId) => new LocalStorageAdapter(`localStorage://?canvasId=${canvasId}`), adapter: (canvasId) => new LocalStorageAdapter(`localStorage://?canvasId=${canvasId}`),
}, },
id: 'demo', id: 'demo',
window: {
defaultSideBarPanel: 'annotations',
sideBarOpenByDefault: true,
},
windows: [{ windows: [{
loadedManifest: 'https://iiif.harvardartmuseums.org/manifests/object/299843', loadedManifest: 'https://iiif.harvardartmuseums.org/manifests/object/299843',
}], }],
......
...@@ -10,6 +10,7 @@ import { v4 as uuid } from 'uuid'; ...@@ -10,6 +10,7 @@ import { v4 as uuid } from 'uuid';
import { PaperContainer } from '@psychobolt/react-paperjs'; import { PaperContainer } from '@psychobolt/react-paperjs';
import { RectangleTool } from '@psychobolt/react-paperjs-editor'; import { RectangleTool } from '@psychobolt/react-paperjs-editor';
import OpenSeadragon from 'openseadragon'; import OpenSeadragon from 'openseadragon';
import WebAnnotation from './WebAnnotation';
/** */ /** */
class AnnotationCreation extends Component { class AnnotationCreation extends Component {
/** */ /** */
...@@ -40,17 +41,12 @@ class AnnotationCreation extends Component { ...@@ -40,17 +41,12 @@ class AnnotationCreation extends Component {
canvases.forEach((canvas) => { canvases.forEach((canvas) => {
const localStorageAdapter = config.annotation.adapter(canvas.id); const localStorageAdapter = config.annotation.adapter(canvas.id);
const anno = { const anno = new WebAnnotation({
body: { body: annoBody,
language: 'en', canvasId: canvas.id,
type: 'TextualBody',
value: annoBody,
},
id: `https://example.org/iiif/book1/page/manifest/${uuid()}`, id: `https://example.org/iiif/book1/page/manifest/${uuid()}`,
motivation: 'commenting', xywh,
target: `${canvas.id}#xywh=${xywh}`, }).toJson();
type: 'Annotation',
};
const newAnnoPage = localStorageAdapter.create(anno); const newAnnoPage = localStorageAdapter.create(anno);
receiveAnnotation(canvas.id, localStorageAdapter.annotationPageId, newAnnoPage); receiveAnnotation(canvas.id, localStorageAdapter.annotationPageId, newAnnoPage);
}); });
...@@ -73,13 +69,16 @@ class AnnotationCreation extends Component { ...@@ -73,13 +69,16 @@ class AnnotationCreation extends Component {
/** */ /** */
addPath(path) { addPath(path) {
// console.log(path); console.log(path);
const { bounds } = path; const { bounds } = path;
const { const {
x, y, width, height, x, y, width, height,
} = bounds; } = bounds;
const point1 = new OpenSeadragon.Point(x, y); const point1 = new OpenSeadragon.Point(x, y);
const point2 = new OpenSeadragon.Point(x + width, y + height); const point2 = new OpenSeadragon.Point(x + width, y + height);
const osdBounds = this.OSDReference.viewer.viewport.getBoundsNoRotate();
console.log(osdBounds);
console.log(path.project.view.bounds);
const viewportPoint1 = this.OSDReference.viewer.viewport.pointFromPixel(point1); const viewportPoint1 = this.OSDReference.viewer.viewport.pointFromPixel(point1);
const viewportPoint2 = this.OSDReference.viewer.viewport.pointFromPixel(point2); const viewportPoint2 = this.OSDReference.viewer.viewport.pointFromPixel(point2);
const viewportWidth = viewportPoint2.x - viewportPoint1.x; const viewportWidth = viewportPoint2.x - viewportPoint1.x;
......
/** */
export default class WebAnnotation {
/** */
constructor({
canvasId, id, xywh, body, svg,
}) {
this.id = id;
this.canvasId = canvasId;
this.xywh = xywh;
this.body = body;
this.svg = svg;
}
/** */
toJson() {
return {
body: {
language: 'en',
type: 'TextualBody',
value: this.body,
},
id: this.id,
motivation: 'commenting',
target: this.target(),
type: 'Annotation',
};
}
/** */
target() {
let target = this.canvasId;
if (this.svg) {
target = {};
target.selector = {
type: 'SvgSelector',
value: this.svg,
};
return target;
}
if (this.xywh) {
target += `#xywh=${this.xywh}`;
}
return target;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment