Select Git revision
AnnotationsOverlayVideo.js
-
Loïs Poujade authored
For a ref to video size/position, use AnnotationsOverlayVideo canvas instead of video element + always show this overlay, even if there is no annotations to display
Loïs Poujade authoredFor a ref to video size/position, use AnnotationsOverlayVideo canvas instead of video element + always show this overlay, even if there is no annotations to display
AnnotationsOverlayVideo.js 22.12 KiB
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import debounce from 'lodash/debounce';
import flatten from 'lodash/flatten';
import sortBy from 'lodash/sortBy';
import xor from 'lodash/xor';
import ResizeObserver from 'react-resize-observer';
import CircularProgress from '@material-ui/core/CircularProgress';
import CanvasOverlayVideo from '../lib/CanvasOverlayVideo';
import CanvasWorld from '../lib/CanvasWorld';
import CanvasAnnotationDisplay from '../lib/CanvasAnnotationDisplay';
import { VideosReferences } from '../plugins/VideosReferences';
/** AnnotationsOverlayVideo - based on AnnotationsOverlay */
export class AnnotationsOverlayVideo extends Component {
/**
* annotationsMatch - compares previous annotations to current to determine
* whether to add a new updateCanvas method to draw annotations
* @param {Array} currentAnnotations
* @param {Array} prevAnnotations
* @return {Boolean}
*/
static annotationsMatch(currentAnnotations, prevAnnotations) {
if (!currentAnnotations && !prevAnnotations) return true;
if (
(currentAnnotations && !prevAnnotations)
|| (!currentAnnotations && prevAnnotations)
) return false;
if (currentAnnotations.length === 0 && prevAnnotations.length === 0) return true;
if (currentAnnotations.length !== prevAnnotations.length) return false;
return currentAnnotations.every((annotation, index) => {
const newIds = annotation.resources.map(r => r.id);
const prevIds = prevAnnotations[index].resources.map(r => r.id);
if (newIds.length === 0 && prevIds.length === 0) return true;
if (newIds.length !== prevIds.length) return false;
if ((annotation.id === prevAnnotations[index].id) && (isEqual(newIds, prevIds))) {
return true;
}
return false;
});
}
/** @private */
static isAnnotaionInTemporalSegment(resource, time) {
const temporalfragment = resource.temporalfragmentSelector;
if (temporalfragment && temporalfragment.length > 0) {
const start = temporalfragment[0] || 0;
const end = (temporalfragment.length > 1) ? temporalfragment[1] : Number.MAX_VALUE;
if (start <= time && time < end) {
//
} else {
return false;
}
}
return true;
}
/**
* @param {Object} props
*/
constructor(props) {
super(props);
this.ref = React.createRef();
VideosReferences.set(props.windowId, this);
this.canvasOverlay = null;
// An initial value for the updateCanvas method