Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

prevent playback with >300 frames

Jason Kentc63664f5b48c
diff --git a/web/css/anim.widget.css b/web/css/anim.widget.css
index ce93ee79f..e0c3590b3 100644
--- a/web/css/anim.widget.css
+++ b/web/css/anim.widget.css
@@ -10,6 +10,7 @@
.wv-animation-widget .input-range.rc-slider-disabled {
cursor: default;
}
+
.wv-animation-widget {
width: 334px;
border-radius: 5px;
@@ -64,6 +65,9 @@
border-radius: 5px;
&.disabled {
cursor: not-allowed;
+ svg.svg-inline--fa:hover {
+ cursor: not-allowed;
+ }
& .wv-animation-widget-icon {
color: rgba(255, 255, 255, 0.3);
opacity: 0.5;
diff --git a/web/js/components/animation-widget/play-button.js b/web/js/components/animation-widget/play-button.js
index 137093bcc..f825150c0 100644
--- a/web/js/components/animation-widget/play-button.js
+++ b/web/js/components/animation-widget/play-button.js
@@ -7,16 +7,22 @@ import { UncontrolledTooltip } from 'reactstrap';
* @class PlayButton
* @extends React.Component
*/
-const PlayButton = (props) => {
- const { playing, pause, play } = props;
+const PlayButton = ({
+ playing, pause, play, isDisabled,
+}) => {
const buttonId = 'play-button';
- const labelText = playing ? 'Pause animation' : 'Play animation';
+ const labelText = isDisabled
+ ? 'Too many animation frames. Reduce time range or increase increment size.'
+ : playing
+ ? 'Pause animation' : 'Play animation';
+ const onClick = isDisabled ? () => {} : playing ? pause : play;
+
return (
<a
id={buttonId}
aria-label={labelText}
- className="wv-anim-play-case wv-icon-case no-drag"
- onClick={playing ? pause : play}
+ className={`wv-anim-play-case wv-icon-case no-drag ${isDisabled ? 'disabled' : ''}`}
+ onClick={onClick}
>
<UncontrolledTooltip
target={buttonId}
@@ -35,6 +41,7 @@ PlayButton.propTypes = {
pause: PropTypes.func,
play: PropTypes.func,
playing: PropTypes.bool,
+ isDisabled: PropTypes.bool,
};
export default PlayButton;
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.js
index a4e1a8475..cc1737892 100644
--- a/web/js/containers/animation-widget.js
+++ b/web/js/containers/animation-widget.js
@@ -94,7 +94,8 @@ const RangeHandle = (props) => {
const widgetWidth = 334;
const subdailyWidgetWidth = 460;
-const maxFrames = 40;
+const maxFrames = 300;
+const maxGifFrames = 40;
/*
* A react component, Builds a rather specific
@@ -349,6 +350,7 @@ class AnimationWidget extends React.Component {
isPlaying,
onPushPause,
hasSubdailyLayers,
+ numberOfFrames,
} = this.props;
const { collapsedWidgetPosition } = this.state;
const cancelSelector = '.no-drag, svg';
@@ -371,6 +373,7 @@ class AnimationWidget extends React.Component {
playing={isPlaying}
play={this.onPushPlay}
pause={onPushPause}
+ isDisabled={numberOfFrames >= maxFrames}
/>
<FontAwesomeIcon icon="chevron-up" className="wv-expand" onClick={this.toggleCollapse} />
<FontAwesomeIcon icon="times" className="wv-close" onClick={onClose} />
@@ -395,9 +398,9 @@ class AnimationWidget extends React.Component {
visibleLayersForProj,
proj,
} = this.props;
- const gifDisabled = numberOfFrames >= maxFrames;
+ const gifDisabled = numberOfFrames >= maxGifFrames;
const elemExists = document.querySelector('#create-gif-button');
- const showWarning = elemExists && numberOfFrames >= maxFrames;
+ const showWarning = elemExists && numberOfFrames >= maxGifFrames;
const warningMessage = (
<span>
Too many frames were selected.
@@ -409,7 +412,7 @@ class AnimationWidget extends React.Component {
const openGif = async () => {
const { startDate, endDate } = this.zeroDates();
- if (numberOfFrames >= maxFrames) {
+ if (numberOfFrames >= maxGifFrames) {
return;
}
const nonDownloadableLayers = hasNonDownloadableLayer ? getNonDownloadableLayers(visibleLayersForProj) : null;
@@ -469,6 +472,7 @@ class AnimationWidget extends React.Component {
interval,
animationCustomModalOpen,
hasSubdailyLayers,
+ numberOfFrames,
} = this.props;
const { speed, widgetPosition } = this.state;
const cancelSelector = '.no-drag, .date-arrows';
@@ -508,6 +512,7 @@ class AnimationWidget extends React.Component {
playing={isPlaying}
play={this.onPushPlay}
pause={onPushPause}
+ isDisabled={numberOfFrames >= maxFrames}
/>
<LoopButton looping={looping} onLoop={this.onLoop} />
@@ -563,7 +568,7 @@ class AnimationWidget extends React.Component {
isDistractionFreeModeActive,
promiseImageryForTime,
selectDate,
- currentDate,
+ snappedCurrentDate,
isGifActive,
delta,
interval,
@@ -578,13 +583,6 @@ class AnimationWidget extends React.Component {
delta,
);
- const snappedCurrentDate = snapToIntervalDelta(
- currentDate,
- startDate,
- endDate,
- interval,
- delta,
- );
if (!isActive) {
return null;
@@ -687,7 +685,7 @@ function mapStateToProps(state) {
const useInterval = customSelected ? customInterval || 3 : interval;
const subDailyInterval = useInterval > 3;
const subDailyMode = subDailyInterval && hasSubdailyLayers;
- const numberOfFrames = util.getNumberOfDays(
+ const numberOfFrames = util.getNumberOfSteps(
startDate,
endDate,
TIME_SCALE_FROM_NUMBER[useInterval],
@@ -696,6 +694,20 @@ function mapStateToProps(state) {
);
const { rotation } = map;
const visibleLayersForProj = lodashFilter(activeLayersForProj, 'visible');
+ const currentDate = getSelectedDate(state);
+ let snappedCurrentDate;
+ if (numberOfFrames <= maxFrames) {
+ snappedCurrentDate = snapToIntervalDelta(
+ currentDate,
+ startDate,
+ endDate,
+ TIME_SCALE_FROM_NUMBER[useInterval],
+ delta,
+ );
+ } else {
+ snappedCurrentDate = currentDate;
+ }
+
return {
appNow,
screenWidth: browser.screenWidth,
@@ -704,7 +716,7 @@ function mapStateToProps(state) {
startDate,
endDate,
activePalettes,
- currentDate: getSelectedDate(state),
+ snappedCurrentDate,
minDate,
maxDate,
isActive: animationIsActive,
@@ -831,7 +843,7 @@ AnimationWidget.propTypes = {
activePalettes: PropTypes.object,
animationCustomModalOpen: PropTypes.bool,
visibleLayersForProj: PropTypes.array,
- currentDate: PropTypes.object,
+ snappedCurrentDate: PropTypes.object,
customDelta: PropTypes.number,
customInterval: PropTypes.number,
delta: PropTypes.number,
diff --git a/web/js/containers/gif.js b/web/js/containers/gif.js
index d1398a9c1..768210300 100644
--- a/web/js/containers/gif.js
+++ b/web/js/containers/gif.js
@@ -410,7 +410,7 @@ function mapStateToProps(state) {
speed,
map,
url,
- numberOfFrames: util.getNumberOfDays(
+ numberOfFrames: util.getNumberOfSteps(
startDate,
endDate,
customSelected
diff --git a/web/js/util/util.js b/web/js/util/util.js
index 7a3a50260..669ed9cfd 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -308,8 +308,7 @@ export default (function(self) {
case 'month':
year = newDate.getUTCFullYear();
month = newDate.getUTCMonth();
- maxDay = new Date(year, month + amount + 1, 0)
- .getUTCDate();
+ maxDay = new Date(year, month + amount + 1, 0).getUTCDate();
if (maxDay <= date.getUTCDate()) {
newDate.setUTCDate(maxDay);
}
@@ -324,12 +323,12 @@ export default (function(self) {
return newDate;
};
- self.getNumberOfDays = function(start, end, interval, increment = 1, maxToCheck) {
+ self.getNumberOfSteps = function(start, end, interval, delta = 1, maxToCheck) {
let i = 1;
let currentDate = start;
while (currentDate < end) {
i += 1;
- currentDate = self.dateAdd(currentDate, interval, increment);
+ currentDate = self.dateAdd(currentDate, interval, delta);
// if checking for a max number limit, break out after reaching it
if (maxToCheck && i >= maxToCheck) {
return i;