Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

animation wip

Benjamin King29f7d6e2de97
diff --git a/web/js/app.js b/web/js/app.js
index 6881f52ac..ce4218aa9 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -23,7 +23,6 @@ import { updateLegacyInitComplete } from './modules/migration/actions';
import { calculateResponsiveState } from 'redux-responsive';
import Tour from './containers/tour';
import Timeline from './containers/timeline/timeline';
-// import AnimationWidget from './containers/animation-widget';
import ErrorBoundary from './containers/error-boundary';
import Debug from './components/util/debug';
@@ -103,7 +102,7 @@ class App extends React.Component {
<Timeline />
<OlCoordinates mouseEvents={this.props.mapMouseEvents} />
{/* <div id="wv-animation-widet-case"> */}
- {/* {config.features.animation ? <AnimationWidget /> : ''} */}
+ {/* {config.features.animation ? <AnimationWidget /> : ''} */}
{/* </div> */}
<Modal />
<ErrorBoundary>
diff --git a/web/js/components/animation-widget/gif-panel.js b/web/js/components/animation-widget/gif-panel.js
index ef42f2f2b..5525e2006 100644
--- a/web/js/components/animation-widget/gif-panel.js
+++ b/web/js/components/animation-widget/gif-panel.js
@@ -4,6 +4,9 @@ import { GifPanelGrid } from './gif-panel-grid';
import Button from '../util/button';
import { Checkbox } from '../util/checkbox';
import PropTypes from 'prop-types';
+import { getDimensions } from '../../modules/image-download/util';
+const MAX_GIF_SIZE = 250;
+const MAX_IMAGE_DIMENSION_SIZE = 8200;
/*
* A react component, Builds a rather specific
@@ -20,20 +23,26 @@ export default class GifPanel extends React.Component {
imgWidth: props.imgWidth,
speed: props.speed,
resolutions: props.resolutions,
- onSelectionChange: props.onSelectionChange,
resolution: props.resolution,
valid: props.valid,
showDates: props.showDates,
increment: props.increment
};
+ this.handleChange = this.handleChange.bind(this);
}
handleChange(type, value) {
this.setState({
resolution: value
});
- this.props.onSelectionChange(value);
}
render() {
+ const { projId, lonlats } = this.props;
+ const { resolution } = this.props;
+ const dimensions = getDimensions(projId, lonlats, resolution);
+ const height = dimensions.height;
+ const width = dimensions.width;
+ const requestSize = ((width * height * 24) / 8388608).toFixed(2);
+ const valid = isFileSizeValid(requestSize, height, width);
return (
<div className="animation-gif-dialog-wrapper">
<div className="gif-selector-case">
@@ -47,23 +56,19 @@ export default class GifPanel extends React.Component {
/>
</div>
<GifPanelGrid
- width={this.state.imgWidth}
- height={this.state.imgHeight}
- requestSize={this.state.requestSize}
- maxGifSize={this.props.maxGifSize}
- maxImageDimensionSize={this.props.maxImageDimensionSize}
- valid={this.state.valid}
+ width={width}
+ height={height}
+ requestSize={((width * height * 24) / 8388608).toFixed(2)}
+ maxGifSize={MAX_GIF_SIZE}
+ maxImageDimensionSize={MAX_IMAGE_DIMENSION_SIZE}
+ valid={valid}
onClick={this.props.onDownloadClick}
startDate={this.state.startDate}
endDate={this.state.endDate}
speed={this.state.speed}
increment={this.state.increment}
/>
- <Button
- onClick={this.props.onClick}
- text="Create GIF"
- valid={this.state.valid}
- />
+ <Button onClick={this.props.onClick} text="Create GIF" valid={valid} />
<Checkbox
id="wv-checkbox-gif"
classNames="wv-checkbox-gif"
@@ -103,3 +108,12 @@ GifPanel.propTypes = {
valid: PropTypes.bool,
increment: PropTypes.string
};
+const isFileSizeValid = function(requestSize, imgHeight, imgWidth) {
+ return (
+ requestSize < MAX_GIF_SIZE &&
+ imgHeight !== 0 &&
+ imgWidth !== 0 &&
+ imgHeight <= MAX_IMAGE_DIMENSION_SIZE &&
+ imgWidth <= MAX_IMAGE_DIMENSION_SIZE
+ );
+};
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.js
index 03b4f8754..c7d5acd39 100644
--- a/web/js/containers/animation-widget.js
+++ b/web/js/containers/animation-widget.js
@@ -19,6 +19,8 @@ import {
changeStartDate,
changeEndDate
} from '../modules/animation/actions';
+import { openCustomContent } from '../modules/modal/actions';
+import GifContainer from './gif';
import { timeScaleFromNumberKey } from '../modules/date/constants';
@@ -56,14 +58,19 @@ class AnimationWidget extends React.Component {
super(props);
this.state = {
speed: props.speed,
- isSliding: false
+ isSliding: false,
+ isGifActive: false
};
+ this.onDateChange = this.onDateChange.bind(this);
}
static getDerivedStateFromProps(props, state) {
if (props.speed !== state.speed && !state.isSliding) {
return { speed: props.speed };
} else return null;
}
+ toggleGIF() {
+ this.setState({ isGifActive: !this.state.isGifActive });
+ }
/*
* Sets a new state to say whether or not
* the animation should loop
@@ -167,19 +174,20 @@ class AnimationWidget extends React.Component {
date={startDate}
id="start"
idSuffix="animation-widget-start"
- onDateChange={this.onDateChange.bind(this)}
+ onDateChange={this.onDateChange}
maxDate={endDate}
minDate={minDate}
hasSubdailyLayers={hasSubdailyLayers}
/>
<div className="thru-label">To</div>
+
<TimeSelector
width="120"
height="30"
date={endDate}
id="end"
idSuffix="animation-widget-end"
- onDateChange={this.onDateChange.bind(this)}
+ onDateChange={this.onDateChange}
maxDate={maxDate}
minDate={startDate}
hasSubdailyLayers={hasSubdailyLayers}
@@ -226,8 +234,18 @@ const mapDispatchToProps = dispatch => ({
onPushLoop: () => {
dispatch(toggleLooping());
},
- onPushGIF: () => {
- // dispatch(onPushGIF());
+ onPushGIF: onToggle => {
+ const customProps = {
+ headerText: null,
+ type: 'toolbar',
+ modalClassName: 'toolbar-list-modal toolbar-modal',
+ backdrop: true,
+ bodyComponent: GifContainer,
+ wrapClassName: 'toolbar_modal_outer toolbar_modal_outer',
+ offsetRight: '40px',
+ toggle: onToggle
+ };
+ dispatch(openCustomContent('GIF_MODAL', customProps));
},
onSlide: num => {
dispatch(changeFrameRate(num));
diff --git a/web/js/containers/animation/gif.js b/web/js/containers/animation/gif.js
deleted file mode 100644
index e69de29bb..000000000
diff --git a/web/js/containers/gif.js b/web/js/containers/gif.js
new file mode 100644
index 000000000..3df42f224
--- /dev/null
+++ b/web/js/containers/gif.js
@@ -0,0 +1,145 @@
+import React, { Component, Fragment } from 'react';
+import PropTypes from 'prop-types';
+import { connect } from 'react-redux';
+import GifPanel from '../components/animation-widget/gif-panel';
+import util from '../util/util';
+import * as olProj from 'ol/proj';
+import { debounce as lodashDebounce } from 'lodash';
+import Crop from '../components/util/image-crop';
+import {
+ resolutionsGeo,
+ resolutionsPolar
+} from '../modules/image-download/constants';
+import {
+ imageUtilCalculateResolution,
+ imageUtilGetCoordsFromPixelValues,
+ getPercentageFromPixel,
+ getPixelFromPercentage
+} from '../modules/image-download/util';
+import { Modal, ModalHeader, ModalBody } from 'reactstrap';
+
+class GIF extends Component {
+ constructor(props) {
+ super(props);
+ const screenHeight = props.screenHeight;
+ const screenWidth = props.screenWidth;
+ this.state = {
+ isDownloaded: false,
+ isDownloadError: false,
+ showDates: true,
+ isValidSelection: true,
+ boundaries: {
+ x: screenWidth / 2 - 100,
+ y: screenHeight / 2 - 100,
+ x2: screenWidth / 2 + 100,
+ y2: screenHeight / 2 + 100
+ }
+ };
+ }
+ onBoundaryChange(boundaries) {
+ const { screenWidth, screenHeight } = this.props;
+ const x = getPixelFromPercentage(screenWidth, boundaries.x);
+ const y = getPixelFromPercentage(screenHeight, boundaries.y);
+ const x2 = x + getPixelFromPercentage(screenWidth, boundaries.width);
+ const y2 = y + getPixelFromPercentage(screenHeight, boundaries.height);
+ this.setState({
+ boundaries: {
+ x: x,
+ y: y,
+ x2: x2,
+ y2: y2
+ }
+ });
+ }
+ render() {
+ const {
+ isActive,
+ increment,
+ animationSpeed,
+ map,
+ screenWidth,
+ screenHeight,
+ proj,
+ onClose
+ } = this.props;
+ const {
+ isDownloaded,
+ isDownloadError,
+ boundaries,
+ showDates,
+ isValidSelection
+ } = this.state;
+ console.log('yolo');
+ const { x, y, x2, y2 } = boundaries;
+ const isGeoProjection = proj.id === 'geographic';
+ const resolutions = isGeoProjection ? resolutionsGeo : resolutionsPolar;
+ const lonlats = imageUtilGetCoordsFromPixelValues(
+ boundaries,
+ map.selectedMap
+ );
+ const crs = proj.crs;
+ const geolonlat1 = olProj.transform(lonlats[0], crs, 'EPSG:4326');
+ const geolonlat2 = olProj.transform(lonlats[1], crs, 'EPSG:4326');
+ const resolution = imageUtilCalculateResolution(
+ Math.round(map.getZoom()),
+ isGeoProjection,
+ proj.resolutions
+ );
+
+ if (!isActive) return '';
+ // TODO if(isDownloaded) return <Down />
+ return (
+ <Fragment>
+ <GifPanel
+ speed={animationSpeed}
+ resolutions={resolutions}
+ resolution={resolution}
+ showDates={showDates}
+ increment={increment}
+ projId={proj.id}
+ lonlats={lonlats}
+ />
+
+ <Crop
+ x={getPercentageFromPixel(screenWidth, x)}
+ y={getPercentageFromPixel(screenHeight, y)}
+ maxHeight={screenHeight}
+ maxWidth={screenWidth}
+ width={getPercentageFromPixel(screenWidth, x2 - x)}
+ height={getPercentageFromPixel(screenHeight, y2 - y)}
+ onChange={lodashDebounce(this.onBoundaryChange.bind(this), 10)}
+ onClose={onClose}
+ coordinates={{
+ bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),
+ topRight: util.formatCoordinate([geolonlat2[0], geolonlat2[1]])
+ }}
+ showCoordinates={false}
+ />
+ </Fragment>
+ );
+ }
+}
+
+function mapStateToProps(state, ownProps) {
+ const { isActive, onClose, increment } = ownProps;
+ const { browser, proj, legacy, animation } = state;
+ const { screenWidth, screenHeight } = browser;
+ return {
+ onClose,
+ screenWidth,
+ screenHeight,
+ proj: proj.selected,
+ isActive: true,
+ increment,
+ map: legacy.map, // TODO replace with just map
+ onClose: () => {}
+ };
+}
+const mapDispatchToProps = dispatch => ({});
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(GIF);
+
+GIF.propTypes = {};
diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.js
index f5baa8b57..ba348502a 100644
--- a/web/js/containers/image-download.js
+++ b/web/js/containers/image-download.js
@@ -38,6 +38,7 @@ class ImageDownloadContainer extends Component {
y2: screenHeight / 2 + 100
}
};
+ this.onBoundaryChange = this.onBoundaryChange.bind(this);
}
onBoundaryChange(boundaries) {
const { screenWidth, screenHeight } = this.props;
@@ -101,7 +102,7 @@ class ImageDownloadContainer extends Component {
maxWidth={screenWidth}
width={getPercentageFromPixel(screenWidth, x2 - x)}
height={getPercentageFromPixel(screenHeight, y2 - y)}
- onChange={debounce(this.onBoundaryChange.bind(this), 10)}
+ onChange={debounce(this.onBoundaryChange, 10)}
onClose={onClose}
bottomLeftStyle={{
left: x,