Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2073: Animation Loading bar (#3797)

Jason Kent7e35877298a8
diff --git a/web/js/components/animation-widget/loading-indicator.js b/web/js/components/animation-widget/loading-indicator.js
new file mode 100644
index 000000000..7b0e75f2b
--- /dev/null
+++ b/web/js/components/animation-widget/loading-indicator.js
@@ -0,0 +1,61 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import {
+ Modal, ModalBody, ModalHeader, Progress,
+} from 'reactstrap';
+import Spinner from 'react-loader';
+
+export default function LoadingIndicator(props) {
+ const {
+ onClose, title, bodyMsg, loadedItems, totalItems,
+ } = props;
+
+ const msgStyle = {
+ minHeight: 30, marginBottom: 50, fontSize: 14, textAlign: 'center',
+ };
+ const barStyle = { margin: 12 };
+ const spinnerStyle = { minHeight: 50 };
+ const progressValue = ((loadedItems / totalItems) * 100).toFixed(0);
+
+ const renderProgressBar = () => (
+ <div style={barStyle}>
+ <Progress
+ animated
+ striped
+ value={progressValue}
+ />
+ </div>
+ );
+
+ const renderSpinner = () => (
+ <div style={spinnerStyle}>
+ <Spinner color="#fff" loaded={false} />
+ </div>
+ );
+
+ return (
+ <Modal
+ isOpen
+ toggle={onClose}
+ size="md"
+ backdrop={false}
+ wrapClassName="clickable-behind-modal"
+ >
+ <ModalHeader toggle={onClose}>{title}</ModalHeader>
+ <ModalBody>
+ {bodyMsg && (
+ <div style={msgStyle}>{bodyMsg}</div>
+ )}
+ {totalItems ? renderProgressBar() : renderSpinner()}
+ </ModalBody>
+ </Modal>
+ );
+}
+
+LoadingIndicator.propTypes = {
+ onClose: PropTypes.func,
+ title: PropTypes.string,
+ bodyMsg: PropTypes.string,
+ loadedItems: PropTypes.number,
+ totalItems: PropTypes.number,
+};
diff --git a/web/js/components/animation-widget/play-queue.js b/web/js/components/animation-widget/play-queue.js
index 247fed090..c00f205fa 100644
--- a/web/js/components/animation-widget/play-queue.js
+++ b/web/js/components/animation-widget/play-queue.js
@@ -2,7 +2,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import PQueue from 'p-queue/dist';
-import PreloadSpinner from './preload-spinner';
+import LoadingIndicator from './loading-indicator';
import util from '../../util/util';
const CONCURRENT_REQUESTS = 3;
@@ -15,6 +15,7 @@ class PlayQueue extends React.Component {
const { numberOfFrames } = props;
this.state = {
isAnimating: false,
+ loadedItems: 0,
};
this.fetchTimes = [0];
this.queue = new PQueue({ concurrency: CONCURRENT_REQUESTS });
@@ -22,7 +23,7 @@ class PlayQueue extends React.Component {
this.bufferObject = {};
this.bufferArray = [];
this.playInterval = 0;
- this.defaultBufferSize = numberOfFrames < 15 ? numberOfFrames : 15;
+ this.defaultBufferSize = numberOfFrames < 10 ? numberOfFrames : 10;
this.minBufferLength = null;
this.canPreloadAll = numberOfFrames <= this.defaultBufferSize;
}
@@ -263,6 +264,7 @@ class PlayQueue extends React.Component {
*/
async addDate(date) {
const { promiseImageryForTime } = this.props;
+ let { loadedItems } = this.state;
const strDate = toString(date);
if (this.inQueueObject[strDate] || this.bufferObject[strDate]) {
return;
@@ -274,6 +276,7 @@ class PlayQueue extends React.Component {
const startTime = Date.now();
await promiseImageryForTime(date);
this.fetchTimes.push(Date.now() - startTime);
+ this.setState({ loadedItems: loadedItems += 1 });
return strDate;
});
@@ -355,14 +358,17 @@ class PlayQueue extends React.Component {
render() {
const { isAnimating } = this.state;
const { onClose } = this.props;
+ const loadedItems = util.objectLength(this.bufferObject);
+ const title = !this.minBufferLength ? 'Determining buffer size...' : 'Preloading buffer...';
return isAnimating
? ''
: (
- <PreloadSpinner
- title="Loading ..."
- bodyMsg="Preloading imagery for smooth animation"
+ <LoadingIndicator
+ title={title}
onClose={onClose}
+ loadedItems={loadedItems}
+ totalItems={this.minBufferLength || 100}
/>
);
}
diff --git a/web/js/components/animation-widget/preload-spinner.js b/web/js/components/animation-widget/preload-spinner.js
deleted file mode 100644
index bc04ab213..000000000
--- a/web/js/components/animation-widget/preload-spinner.js
+++ /dev/null
@@ -1,37 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-import { Modal, ModalBody, ModalHeader } from 'reactstrap';
-import Spinner from 'react-loader';
-
-export default function PreloadSpinner({ onClose, title, bodyMsg }) {
- return (
- <Modal
- isOpen
- toggle={onClose}
- size="sm"
- backdrop={false}
- wrapClassName="clickable-behind-modal"
- >
- <ModalHeader toggle={onClose}>{title}</ModalHeader>
- <ModalBody>
- {bodyMsg && (
- <div style={{
- minHeight: 30, marginBottom: 30, fontSize: 14,
- }}
- >
- {bodyMsg}
- </div>
- )}
- <div style={{ minHeight: 50 }}>
- <Spinner color="#fff" loaded={false} />
- </div>
- </ModalBody>
- </Modal>
- );
-}
-
-PreloadSpinner.propTypes = {
- onClose: PropTypes.func,
- title: PropTypes.string,
- bodyMsg: PropTypes.string,
-};
diff --git a/web/js/components/timeline/timeline-controls/date-change-arrows.js b/web/js/components/timeline/timeline-controls/date-change-arrows.js
index ae03d7a7a..3f643590f 100644
--- a/web/js/components/timeline/timeline-controls/date-change-arrows.js
+++ b/web/js/components/timeline/timeline-controls/date-change-arrows.js
@@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import HoverTooltip from '../../util/hover-tooltip';
-import PreloadSpinner from '../../animation-widget/preload-spinner';
+import LoadingIndicator from '../../animation-widget/loading-indicator';
import {
setArrowDown as setArrowDownAction,
setArrowUp as setArrowUpAction,
@@ -111,7 +111,7 @@ class DateChangeArrows extends PureComponent {
return (
<div>
{arrowDown && !tilesPreloaded && (
- <PreloadSpinner
+ <LoadingIndicator
title="Loading ..."
bodyMsg="Keep holding to animate the map!"
/>