diff --git a/src/components/OpenSeadragonViewer.js b/src/components/OpenSeadragonViewer.js index 5db718e757bf8beb8d02e298b6a7e05f963e8853..461ebdbc7bd36c97227fb2005f2d7dac0ae25820 100644 --- a/src/components/OpenSeadragonViewer.js +++ b/src/components/OpenSeadragonViewer.js @@ -36,6 +36,14 @@ export class OpenSeadragonViewer extends Component { }); } + /** */ + static resourceClip(contentResource) { + const fragmentMatch = contentResource.id.match(/xywh=(.*)$/); + if (!fragmentMatch) return undefined; + const bounds = fragmentMatch[1].split(',').map(str => parseInt(str, 10)); + return new OpenSeadragon.Rect(...bounds); + } + /** * @param {Object} props */ @@ -223,7 +231,10 @@ export class OpenSeadragonViewer extends Component { if (!this.viewer) { return; } + + const clip = OpenSeadragonViewer.resourceClip(contentResource); this.viewer.addSimpleImage({ + ...(clip && { clip }), error: event => reject(event), fitBounds: new OpenSeadragon.Rect( ...canvasWorld.contentResourceToWorldCoordinates(contentResource), @@ -249,8 +260,10 @@ export class OpenSeadragonViewer extends Component { const contentResource = canvasWorld.contentResource(infoResponse.id); if (!contentResource) return; + const clip = OpenSeadragonViewer.resourceClip(contentResource); this.viewer.addTiledImage({ + ...(clip && { clip }), error: event => reject(event), fitBounds: new OpenSeadragon.Rect( ...canvasWorld.contentResourceToWorldCoordinates(contentResource),