diff --git a/__tests__/src/components/OpenSeadragonViewer.test.js b/__tests__/src/components/OpenSeadragonViewer.test.js index 799ac2d70a465ee0334647b544312fd192229e0c..5ea1e47d055691a762e93c593b8952ebd45c21fb 100644 --- a/__tests__/src/components/OpenSeadragonViewer.test.js +++ b/__tests__/src/components/OpenSeadragonViewer.test.js @@ -26,14 +26,20 @@ describe('OpenSeadragonViewer', () => { wrapper = shallow( <OpenSeadragonViewer classes={{}} - tileSources={[{ - '@id': 'http://foo', - height: 200, - width: 100, + infoResponses={[{ + id: 'a', + json: { + '@id': 'http://foo', + height: 200, + width: 100, + }, }, { - '@id': 'http://bar', - height: 201, - width: 150, + id: 'b', + json: { + '@id': 'http://bar', + height: 201, + width: 150, + }, }]} nonTiledImages={[{ id: 'http://foo', @@ -105,19 +111,22 @@ describe('OpenSeadragonViewer', () => { }); }); - describe('tileSourcesMatch', () => { + describe('infoResponsesMatch', () => { it('when they do not match', () => { - expect(wrapper.instance().tileSourcesMatch([])).toBe(false); + expect(wrapper.instance().infoResponsesMatch([])).toBe(false); }); it('with an empty array', () => { wrapper.instance().viewer = { close: () => {}, }; - wrapper.setProps({ tileSources: [] }); - expect(wrapper.instance().tileSourcesMatch([])).toBe(true); + wrapper.setProps({ infoResponses: [] }); + expect(wrapper.instance().infoResponsesMatch([])).toBe(true); }); it('when the @ids do match', () => { - expect(wrapper.instance().tileSourcesMatch([{ '@id': 'http://foo' }])).toBe(true); + expect(wrapper.instance().infoResponsesMatch([{ id: 'a', json: { '@id': 'http://foo' } }])).toBe(true); + }); + it('when the @ids do not match', () => { + expect(wrapper.instance().infoResponsesMatch([{ id: 'a', json: { '@id': 'http://foo-degraded' } }])).toBe(false); }); }); @@ -142,7 +151,7 @@ describe('OpenSeadragonViewer', () => { wrapper.instance().viewer = { close: () => {}, }; - wrapper.setProps({ tileSources: [1, 2, 3, 4] }); + wrapper.setProps({ infoResponses: [1, 2, 3, 4] }); const mockAddTileSource = jest.fn(); wrapper.instance().addTileSource = mockAddTileSource; wrapper.instance().addAllImageSources(); diff --git a/src/components/OpenSeadragonViewer.js b/src/components/OpenSeadragonViewer.js index 7fc7c8932adfecb1c1a743b0d941ebe24d55f30f..6d9b652d3cc4e6700fda4897b1793947c055108b 100644 --- a/src/components/OpenSeadragonViewer.js +++ b/src/components/OpenSeadragonViewer.js @@ -124,7 +124,7 @@ export class OpenSeadragonViewer extends Component { this.viewer.forceRedraw(); } - if (!this.tileSourcesMatch(prevProps.tileSources) + if (!this.infoResponsesMatch(prevProps.infoResponses) || !this.nonTiledImagedMatch(prevProps.nonTiledImages) ) { this.viewer.close(); @@ -204,12 +204,12 @@ export class OpenSeadragonViewer extends Component { /** */ addAllImageSources() { - const { nonTiledImages, tileSources } = this.props; + const { nonTiledImages, infoResponses } = this.props; Promise.all( - tileSources.map(tileSource => this.addTileSource(tileSource)), + infoResponses.map(infoResponse => this.addTileSource(infoResponse)), nonTiledImages.map(image => this.addNonTiledImage(image)), ).then(() => { - if (tileSources[0] || nonTiledImages[0]) { + if (infoResponses[0] || nonTiledImages[0]) { this.zoomToWorld(); } }); @@ -237,14 +237,15 @@ export class OpenSeadragonViewer extends Component { /** */ - addTileSource(tileSource) { + addTileSource(infoResponse) { const { canvasWorld } = this.props; return new Promise((resolve, reject) => { if (!this.viewer) { return; } - const contentResource = canvasWorld.contentResource(tileSource); + const tileSource = infoResponse.json; + const contentResource = canvasWorld.contentResource(infoResponse); if (!contentResource) return; @@ -288,22 +289,28 @@ export class OpenSeadragonViewer extends Component { } /** - * tileSourcesMatch - compares previous tileSources to current to determine + * infoResponsesMatch - compares previous tileSources to current to determine * whether a refresh of the OSD viewer is needed. * @param {Array} prevTileSources * @return {Boolean} */ - tileSourcesMatch(prevTileSources) { - const { tileSources } = this.props; - if (tileSources.length === 0 && prevTileSources.length === 0) return true; + infoResponsesMatch(prevInfoResponses) { + const { infoResponses } = this.props; + if (infoResponses.length === 0 && prevInfoResponses.length === 0) return true; - return tileSources.some((tileSource, index) => { - if (!prevTileSources[index]) { + return infoResponses.some((infoResponse, index) => { + if (!prevInfoResponses[index]) { return false; } - if (tileSource['@id'] === prevTileSources[index]['@id']) { + + if (!infoResponse.json) { + return false; + } + + if (infoResponse.json['@id'] === (prevInfoResponses[index].json || {})['@id']) { return true; } + return false; }); } @@ -390,6 +397,7 @@ export class OpenSeadragonViewer extends Component { OpenSeadragonViewer.defaultProps = { children: null, highlightedAnnotations: [], + infoResponses: [], label: null, nonTiledImages: [], osdConfig: {}, @@ -397,7 +405,6 @@ OpenSeadragonViewer.defaultProps = { searchAnnotations: [], selectedAnnotations: [], selectedContentSearchAnnotations: [], - tileSources: [], viewer: null, }; @@ -406,6 +413,7 @@ OpenSeadragonViewer.propTypes = { children: PropTypes.node, classes: PropTypes.objectOf(PropTypes.string).isRequired, highlightedAnnotations: PropTypes.arrayOf(PropTypes.object), + infoResponses: PropTypes.arrayOf(PropTypes.object), label: PropTypes.string, nonTiledImages: PropTypes.array, // eslint-disable-line react/forbid-prop-types osdConfig: PropTypes.object, // eslint-disable-line react/forbid-prop-types @@ -414,7 +422,6 @@ OpenSeadragonViewer.propTypes = { selectedAnnotations: PropTypes.arrayOf(PropTypes.object), selectedContentSearchAnnotations: PropTypes.arrayOf(PropTypes.object), t: PropTypes.func.isRequired, - tileSources: PropTypes.arrayOf(PropTypes.object), updateViewport: PropTypes.func.isRequired, viewer: PropTypes.object, // eslint-disable-line react/forbid-prop-types windowId: PropTypes.string.isRequired, diff --git a/src/components/WindowViewer.js b/src/components/WindowViewer.js index d9edb23936363686dd64df6ae7b89441f46d6e3c..763d627c20326be616edfd13556160bc6ffbfa65 100644 --- a/src/components/WindowViewer.js +++ b/src/components/WindowViewer.js @@ -106,9 +106,8 @@ export class WindowViewer extends Component { /** * Return an image information response from the store for the correct image */ - tileInfoFetchedFromStore() { - const responses = this.currentInfoResponses() - .map(infoResponse => infoResponse.json); + infoResponsesFetchedFromStore() { + const responses = this.currentInfoResponses(); // Only return actual tileSources when all current canvases have completed. if (responses.length === this.imageServiceIds().length) { return responses; @@ -130,7 +129,7 @@ export class WindowViewer extends Component { return ( <OSDViewer - tileSources={this.tileInfoFetchedFromStore()} + infoResponses={this.infoResponsesFetchedFromStore()} windowId={windowId} > <WindowCanvasNavigationControls key="canvas_nav" windowId={windowId} /> diff --git a/src/lib/CanvasWorld.js b/src/lib/CanvasWorld.js index b7b9b66fe90af1684d4b12d9e034a0a152c19637..e74ab23dccd9dff59aca0b47efa675cf0bd34e5e 100644 --- a/src/lib/CanvasWorld.js +++ b/src/lib/CanvasWorld.js @@ -57,8 +57,8 @@ export default class CanvasWorld { } /** Get the IIIF content resource for an image */ - contentResource(tileSource) { - const imageId = tileSource['@id']; + contentResource(infoResponse) { + const imageId = infoResponse.id; const manifestoCanvas = this.canvases.find(c => c.imageServiceIds.some(id => ( normalizeUrl(id, { stripAuthentication: false }) === normalizeUrl(imageId, { stripAuthentication: false }))));