Skip to content
Snippets Groups Projects
Select Git revision
  • 1c35cc4ada374a9bfe855f97b7d1ac11c03af72a
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

WindowViewer.js

Blame
  • WindowViewer.js 2.01 KiB
    import React, { Component, Fragment } from 'react';
    import PropTypes from 'prop-types';
    import fetch from 'node-fetch';
    import miradorWithPlugins from '../lib/miradorWithPlugins';
    import OpenSeadragonViewer from './OpenSeadragonViewer';
    import ViewerNavigation from './ViewerNavigation';
    
    /**
     * Represents a WindowViewer in the mirador workspace. Responsible for mounting
     * OSD and Navigation
     */
    class WindowViewer extends Component {
      /**
       * @param {Object} props
       */
      constructor(props) {
        super(props);
    
        const { manifest } = this.props;
        this.canvases = manifest.manifestation.getSequences()[0].getCanvases();
        this.state = {
          tileSources: [],
        };
      }
    
      /**
       * componentDidMount - React lifecycle method
       * Request the initial canvas on mount
       */
      componentDidMount() {
        this.requestAndUpdateTileSources();
      }
    
      /**
       * componentDidUpdate - React lifecycle method
       * Request a new canvas if it is needed
       */
      componentDidUpdate(prevProps) {
        const { window } = this.props;
        if (prevProps.window.canvasIndex !== window.canvasIndex) {
          this.requestAndUpdateTileSources();
        }
      }
    
      /**
       */
      requestAndUpdateTileSources() {
        const { window } = this.props;
        fetch(`${this.canvases[window.canvasIndex].getImages()[0].getResource().getServices()[0].id}/info.json`)
          .then(response => response.json())
          .then((json) => {
            this.setState({
              tileSources: [json],
            });
          });
      }
    
      /**
       * Renders things
       */
      render() {
        const { window } = this.props;
        const { tileSources } = this.state;
        return (
          <Fragment>
            <OpenSeadragonViewer tileSources={tileSources} window={window} />
            <ViewerNavigation window={window} canvases={this.canvases} />
          </Fragment>
        );
      }
    }
    
    WindowViewer.propTypes = {
      manifest: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
      window: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
    };
    
    export default miradorWithPlugins(WindowViewer);