Skip to content
Snippets Groups Projects
Select Git revision
  • 9d2154f83438b74de7d17707831dea2c50ad373e
  • annotation-on-video default protected
  • demo_ci
  • 3-upstream-01022023
  • master
  • gh3538-captions
  • 16-adapt-for-images-annot
  • 15-api-for-annotations-on-video
  • 15-annotations-on-videos
  • video_for_annotations
  • wip-1-annotations-on-videos
  • 9-videoviewer-tests
  • 9_wip_videotests
  • 6-fix-tests-and-ci
  • _fix_ci
  • wip-webpack-from-git
16 results

ViewerNavigationVideo.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);