Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

separate out render methods, make widget draggable

Jason Kent53dd1350abbf
diff --git a/web/css/anim.widget.css b/web/css/anim.widget.css
index bc0b2cfd3..70dfe6124 100644
--- a/web/css/anim.widget.css
+++ b/web/css/anim.widget.css
@@ -1,7 +1,9 @@
.wv-animation-widget-wrapper {
position: absolute;
bottom: 88px;
- left: 40%;
+ /* left: 50%;
+ transform: translateX(-50%);
+ -webkit-transform: translate(-50%); */
z-index: 100;
&.minimized {
bottom: 80px;
@@ -11,15 +13,6 @@
}
}
}
-.wv-animation-widget-wrapper-minimized {
- position: absolute;
- z-index: 100;
- bottom: 80px;
- left: 242px;
- &.subdaily {
- left: 347px;
- }
-}
.wv-animation-widget {
width: 334px;
border-radius: 8px;
@@ -35,7 +28,7 @@
}
& .wv-animation-widget-header {
display: block;
- margin-bottom: 10px;
+ margin: 7px 0 10px 20px;
text-transform: capitalize;
& .interval-btn-container,
& .interval-btn.interval-btn-active {
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.js
index 0ed5ebec7..9cb68495c 100644
--- a/web/js/containers/animation-widget.js
+++ b/web/js/containers/animation-widget.js
@@ -93,6 +93,10 @@ class AnimationWidget extends React.Component {
isGifActive: false,
hoverGif: false,
customIntervalModalOpen: false,
+ widgetPosition: {
+ x: props.screenWidth / 2 - 115,
+ y: 0
+ },
collapsed: false,
collapsedWidgePosition: { x: 0, y: 0 }
};
@@ -104,6 +108,7 @@ class AnimationWidget extends React.Component {
this.handleDragStart = this.handleDragStart.bind(this);
this.toggleCollapse = this.toggleCollapse.bind(this);
this.onCollapsedDrag = this.onCollapsedDrag.bind(this);
+ this.onExpandedDrag = this.onExpandedDrag.bind(this);
}
static getDerivedStateFromProps(props, state) {
@@ -113,9 +118,7 @@ class AnimationWidget extends React.Component {
}
toggleCollapse() {
- this.setState({
- collapsed: !this.state.collapsed
- });
+ this.setState({ collapsed: !this.state.collapsed });
}
/**
@@ -135,6 +138,11 @@ class AnimationWidget extends React.Component {
return draggableTargets.some(tClass => classList.contains(tClass));
}
+ onExpandedDrag(e, position) {
+ const { x, y } = position;
+ this.setState({ widgetPosition: { x, y } });
+ };
+
onCollapsedDrag(e, position) {
const { x, y } = position;
this.setState({ collapsedWidgePosition: { x, y } });
@@ -349,7 +357,37 @@ class AnimationWidget extends React.Component {
);
}
- render() {
+ renderCollapsedWidget() {
+ const {
+ isPlaying,
+ onPushPause,
+ hasSubdailyLayers
+ } = this.props;
+ return (
+ <Draggable
+ bounds="body"
+ onStart={this.handleDragStart}
+ position={this.state.collapsedWidgePosition}
+ onDrag={this.onCollapsedDrag}>
+ <div
+ className={'wv-animation-widget-wrapper minimized' + (hasSubdailyLayers ? ' subdaily' : '')}>
+ <div
+ id="wv-animation-widget"
+ className={'wv-animation-widget minimized'}>
+ <PlayButton
+ playing={isPlaying}
+ play={this.onPushPlay}
+ pause={onPushPause}
+ />
+ <i className="fa fa-external-link-square-alt wv-expand" onClick={this.toggleCollapse} />
+ <i className="fa fa-times wv-close" onClick={this.props.onClose} />
+ </div>
+ </div>
+ </Draggable>
+ );
+ }
+
+ renderExpandedWidget() {
const {
looping,
isPlaying,
@@ -359,17 +397,7 @@ class AnimationWidget extends React.Component {
startDate,
endDate,
onPushPause,
- isActive,
- layers,
- hasCustomPalettes,
- promiseImageryForTime,
- map,
- selectDate,
- currentDate,
- toggleGif,
- isGifActive,
subDailyMode,
- delta,
interval,
customSelected,
customDelta,
@@ -378,82 +406,157 @@ class AnimationWidget extends React.Component {
animationCustomModalOpen,
hasSubdailyLayers
} = this.props;
+ const { speed } = this.state;
+ const gifDisabled = numberOfFrames >= 40;
+ // const defaultPosition = { x: '-50%', y: 0 };
- const { speed, collapsed } = this.state;
-
- if (!isActive) {
- return null;
- }
- if (isGifActive) {
- return <GifContainer onClose={toggleGif} />;
- }
- if (collapsed) {
- const maxLength = getMaxQueueLength(speed);
- const queueLength = getQueueLength(
- startDate,
- endDate,
- speed,
- interval,
- delta
- );
+ return (
+ <Draggable
+ bounds="body"
+ // defaultPosition={defaultPosition}
+ position={this.state.widgetPosition}
+ onDrag={this.onExpandedDrag}
+ onStart={this.handleDragStart}>
+ <div className="wv-animation-widget-wrapper">
+ <div
+ id="wv-animation-widget"
+ className={'wv-animation-widget' + (subDailyMode ? ' subdaily' : '')}
+ >
+ <div className="wv-animation-widget-header">
+ {'Animate Map in '}
+ <TimeScaleIntervalChange
+ setTimeScaleIntervalChangeUnit={this.onIntervalSelect}
+ customIntervalZoomLevel={timeScaleFromNumberKey[customInterval]}
+ customSelected={customSelected}
+ customDelta={customDelta}
+ timeScaleChangeUnit={interval}
+ hasSubdailyLayers={hasSubdailyLayers}
+ />
+ {' Increments'}
+ </div>
- return (
- <ErrorBoundary>
- {isPlaying && (
- <PlayQueue
- endDate={endDate}
- loop={looping}
- isPlaying={isPlaying}
- currentDate={currentDate}
- canPreloadAll={queueLength <= maxLength}
- startDate={startDate}
- hasCustomPalettes={hasCustomPalettes}
- map={map}
- maxQueueLength={maxLength}
- queueLength={queueLength}
- layers={layers}
- interval={interval}
- delta={delta}
- speed={speed}
- selectDate={selectDate}
- togglePlaying={onPushPause}
- promiseImageryForTime={promiseImageryForTime}
- onClose={onPushPause}
+ <PlayButton
+ playing={isPlaying}
+ play={this.onPushPlay}
+ pause={onPushPause}
/>
- )}
- <Draggable
- bounds="body"
- onStart={this.handleDragStart}
- position={this.state.collapsedWidgePosition}
- onDrag={this.onCollapsedDrag}>
- <div id="wv-anim-minimized" className={'wv-animation-widget-wrapper-minimized' + (hasSubdailyLayers ? ' subdaily' : '')}>
- <div
- id="wv-animation-widget"
- className={'wv-animation-widget minimized'}>
- <PlayButton
- playing={isPlaying}
- play={this.onPushPlay}
- pause={onPushPause}
- />
- <i className="fa fa-external-link-square-alt wv-expand" onClick={this.toggleCollapse} />
- <i className="fa fa-times wv-close" onClick={this.props.onClose} />
- </div>
+ <LoopButton looping={looping} onLoop={this.onLoop} />
+
+ {/* FPS slider */}
+ <div className="wv-slider-case">
+ <Slider
+ className="input-range"
+ step={0.5}
+ max={10}
+ min={0.5}
+ value={this.state.speed}
+ onChange={num => this.setState({ speed: num })}
+ handle={RangeHandle}
+ onBeforeChange={() => this.setState({ isSliding: true })}
+ onAfterChange={() => {
+ this.setState({ isSliding: false });
+ this.props.onSlide(speed);
+ }}
+ />
+ <span className="wv-slider-label">{sliderLabel}</span>
</div>
- </Draggable>
- </ErrorBoundary>
- );
- }
- const maxLength = getMaxQueueLength(this.state.speed);
+ {/* Create Gif */}
+ <a
+ id="create-gif-button"
+ title={!gifDisabled ? 'Create Animated GIF' : ''}
+ className={gifDisabled ? 'wv-icon-case disabled' : 'wv-icon-case'}
+ onClick={this.openGif}
+ onMouseEnter={this.toggleHoverGif}
+ onMouseLeave={this.toggleHoverGif}
+ >
+ <i
+ id="wv-animation-widget-file-video-icon"
+ className="fas fa-file-video wv-animation-widget-icon"
+ />
+ </a>
+ {this.renderToolTip()}
+
+ {/* From/To Date/Time Selection */}
+ <div className="wv-anim-dates-case">
+ <TimeSelector
+ id="start"
+ idSuffix="animation-widget-start"
+ width="120"
+ height="30"
+ date={startDate}
+ onDateChange={this.onDateChange}
+ maxDate={endDate}
+ minDate={minDate}
+ subDailyMode={subDailyMode}
+ />
+ <div className="thru-label">To</div>
+ <TimeSelector
+ id="end"
+ idSuffix="animation-widget-end"
+ width="120"
+ height="30"
+ date={endDate}
+ onDateChange={this.onDateChange}
+ maxDate={maxDate}
+ minDate={startDate}
+ subDailyMode={subDailyMode}
+ />
+ </div>
+
+ <i className="fa fa-minus wv-minimize" onClick={this.toggleCollapse} />
+ <i className="fa fa-times wv-close" onClick={this.props.onClose} />
+
+ {/* Custom time interval selection */}
+ <CustomIntervalSelectorWidget
+ customDelta={customDelta}
+ customIntervalZoomLevel={customInterval}
+ customIntervalModalOpen={animationCustomModalOpen}
+ changeCustomInterval={this.changeCustomInterval}
+ hasSubdailyLayers={hasSubdailyLayers}
+ />
+ </div>
+ </div>
+ </Draggable>
+ );
+ }
+
+ render() {
+ const {
+ looping,
+ isPlaying,
+ startDate,
+ endDate,
+ onPushPause,
+ isActive,
+ layers,
+ hasCustomPalettes,
+ promiseImageryForTime,
+ map,
+ selectDate,
+ currentDate,
+ toggleGif,
+ isGifActive,
+ delta,
+ interval
+ } = this.props;
+
+ const { speed, collapsed } = this.state;
+ const maxLength = getMaxQueueLength(speed);
const queueLength = getQueueLength(
startDate,
endDate,
- this.state.speed,
+ speed,
interval,
delta
);
- const gifDisabled = numberOfFrames >= 40;
+ if (!isActive) {
+ return null;
+ }
+ if (isGifActive) {
+ return <GifContainer onClose={toggleGif} />;
+ }
return (
<ErrorBoundary>
{isPlaying && (
@@ -478,108 +581,9 @@ class AnimationWidget extends React.Component {
onClose={onPushPause}
/>
)}
- <Draggable bounds="body" onStart={this.handleDragStart}>
- <div id="wv-anim-widget" className="wv-animation-widget-wrapper">
- <div
- id="wv-animation-widget"
- className={'wv-animation-widget' + (subDailyMode ? ' subdaily' : '')}
- >
- <div className="wv-animation-widget-header">
- {'Animate Map in '}
- <TimeScaleIntervalChange
- setTimeScaleIntervalChangeUnit={this.onIntervalSelect}
- customIntervalZoomLevel={timeScaleFromNumberKey[customInterval]}
- customSelected={customSelected}
- customDelta={customDelta}
- timeScaleChangeUnit={interval}
- hasSubdailyLayers={hasSubdailyLayers}
- />
- {' Increments'}
- </div>
-
- <PlayButton
- playing={isPlaying}
- play={this.onPushPlay}
- pause={onPushPause}
- />
- <LoopButton looping={looping} onLoop={this.onLoop} />
-
- {/* FPS slider */}
- <div className="wv-slider-case">
- <Slider
- className="input-range"
- step={0.5}
- max={10}
- min={0.5}
- value={this.state.speed}
- onChange={num => this.setState({ speed: num })}
- handle={RangeHandle}
- onBeforeChange={() => this.setState({ isSliding: true })}
- onAfterChange={() => {
- this.setState({ isSliding: false });
- this.props.onSlide(this.state.speed);
- }}
- />
- <span className="wv-slider-label">{sliderLabel}</span>
- </div>
-
- {/* Create Gif */}
- <a
- id="create-gif-button"
- title={!gifDisabled ? 'Create Animated GIF' : ''}
- className={gifDisabled ? 'wv-icon-case disabled' : 'wv-icon-case'}
- onClick={this.openGif}
- onMouseEnter={this.toggleHoverGif}
- onMouseLeave={this.toggleHoverGif}
- >
- <i
- id="wv-animation-widget-file-video-icon"
- className="fas fa-file-video wv-animation-widget-icon"
- />
- </a>
- {this.renderToolTip()}
-
- {/* From/To Date/Time Selection */}
- <div className="wv-anim-dates-case">
- <TimeSelector
- id="start"
- idSuffix="animation-widget-start"
- width="120"
- height="30"
- date={startDate}
- onDateChange={this.onDateChange}
- maxDate={endDate}
- minDate={minDate}
- subDailyMode={subDailyMode}
- />
- <div className="thru-label">To</div>
- <TimeSelector
- id="end"
- idSuffix="animation-widget-end"
- width="120"
- height="30"
- date={endDate}
- onDateChange={this.onDateChange}
- maxDate={maxDate}
- minDate={startDate}
- subDailyMode={subDailyMode}
- />
- </div>
-
- <i className="fa fa-minus wv-minimize" onClick={this.toggleCollapse} />
- <i className="fa fa-times wv-close" onClick={this.props.onClose} />
-
- {/* Custom time interval selection */}
- <CustomIntervalSelectorWidget
- customDelta={customDelta}
- customIntervalZoomLevel={customInterval}
- customIntervalModalOpen={animationCustomModalOpen}
- changeCustomInterval={this.changeCustomInterval}
- hasSubdailyLayers={hasSubdailyLayers}
- />
- </div>
- </div>
- </Draggable>
+
+ {collapsed ? this.renderCollapsedWidget() : this.renderExpandedWidget()}
+
</ErrorBoundary>
);
}
@@ -644,6 +648,7 @@ function mapStateToProps(state) {
);
return {
+ screenWidth: browser.screenWidth,
animationCustomModalOpen,
customSelected,
startDate,