Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

gif wip

Benjamin King317dc9bd998e
diff --git a/web/css/modal.css b/web/css/modal.css
index 789dc3535..0cb07880e 100644
--- a/web/css/modal.css
+++ b/web/css/modal.css
@@ -34,3 +34,6 @@
.modal-dialog.light .modal-header .close:hover {
color: #000;
}
+.dynamic-modal.modal-dialog {
+ position: absolute
+}
\ No newline at end of file
diff --git a/web/js/components/animation-widget/gif-panel.js b/web/js/components/animation-widget/gif-panel.js
index 5525e2006..e06768b4f 100644
--- a/web/js/components/animation-widget/gif-panel.js
+++ b/web/js/components/animation-widget/gif-panel.js
@@ -36,47 +36,60 @@ export default class GifPanel extends React.Component {
});
}
render() {
- const { projId, lonlats } = this.props;
- const { resolution } = this.props;
+ const {
+ projId,
+ lonlats,
+ startDate,
+ endDate,
+ onCheck,
+ checked
+ } = this.props;
+ const { resolution } = this.state;
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">
- {this.props.firstLabel}
- <SelectionList
- id="gif-resolution"
- optionArray={this.state.resolutions}
- value={this.state.resolution}
- optionName="resolution"
- onChange={this.handleChange.bind(this)}
+ <div className="gif-dialog">
+ <div className="animation-gif-dialog-wrapper">
+ <div className="gif-selector-case">
+ {this.props.firstLabel}
+ <SelectionList
+ id="gif-resolution"
+ optionArray={this.state.resolutions}
+ value={this.state.resolution}
+ optionName="resolution"
+ onChange={this.handleChange.bind(this)}
+ />
+ </div>
+ <GifPanelGrid
+ 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={startDate}
+ endDate={endDate}
+ speed={this.state.speed}
+ increment={this.state.increment}
+ />
+ <Button
+ onClick={() => this.props.onClick(width, height)}
+ text="Create GIF"
+ valid={valid}
+ />
+ <Checkbox
+ id="wv-checkbox-gif"
+ classNames="wv-checkbox-gif"
+ title="Check box to remove dates from Animating GIF"
+ checked={checked}
+ onCheck={onCheck}
+ label="Include Date Stamps"
/>
</div>
- <GifPanelGrid
- 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={valid} />
- <Checkbox
- id="wv-checkbox-gif"
- classNames="wv-checkbox-gif"
- title="Check box to remove dates from Animating GIF"
- checked={this.props.checked}
- onCheck={this.props.onCheck}
- label="Include Date Stamps"
- />
</div>
);
}
diff --git a/web/js/components/image-download/panel.js b/web/js/components/image-download/panel.js
index 4f4c3264f..98cceea4b 100644
--- a/web/js/components/image-download/panel.js
+++ b/web/js/components/image-download/panel.js
@@ -36,16 +36,12 @@ export default class ImageResSelection extends React.Component {
};
}
onDownload(imgWidth, imgHeight) {
- const { models, url, lonlats, crs } = this.props;
+ const { getLayers, url, lonlats, crs, proj, date } = this.props;
const { fileType, isWorldfile, resolution } = this.state;
- let time = new Date(models.date[models.date.activeDate].getTime());
+ let time = new Date(date.getTime());
time.setUTCHours(0, 0, 0, 0);
-
- let layerList = models.layers.get({
- reverse: true,
- renderable: true
- });
- let layers = imageUtilGetLayers(layerList, models.proj.selected.id);
+ let layerList = getLayers();
+ let layers = imageUtilGetLayers(layerList, proj.id);
let opacities = imageUtilGetLayerOpacities(layerList);
let params = [
@@ -207,7 +203,6 @@ ImageResSelection.propTypes = {
worldFileOptions: PropTypes.bool,
secondLabel: PropTypes.string,
fileTypeOptions: PropTypes.bool,
- models: PropTypes.object,
url: PropTypes.string,
crs: PropTypes.string
};
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.js
index c7d5acd39..3962fd761 100644
--- a/web/js/containers/animation-widget.js
+++ b/web/js/containers/animation-widget.js
@@ -118,6 +118,7 @@ class AnimationWidget extends React.Component {
onPushPlay,
onPushPause
} = this.props;
+ if (this.state.isGifActive) return '';
return (
<ErrorBoundary>
<div
@@ -160,7 +161,10 @@ class AnimationWidget extends React.Component {
href="javascript:void(null)"
title="Create Animated GIF"
className="wv-icon-case"
- onClick={this.props.onPushGIF}
+ onClick={() => {
+ this.toggleGIF();
+ this.props.onPushGIF(this.toggleGIF);
+ }}
>
<i
id="wv-animation-widget-file-video-icon"
@@ -236,13 +240,14 @@ const mapDispatchToProps = dispatch => ({
},
onPushGIF: onToggle => {
const customProps = {
- headerText: null,
- type: 'toolbar',
- modalClassName: 'toolbar-list-modal toolbar-modal',
- backdrop: true,
+ headerText: 'Create An Animated GIF',
+ backdrop: false,
+ wrapClassName: 'clickable-behind-modal toolbar_modal_outer',
+ width: 342,
+ type: 'selection',
+ dynamicOffsets: true,
+ modalClassName: 'gif-modal dynamic-modal',
bodyComponent: GifContainer,
- wrapClassName: 'toolbar_modal_outer toolbar_modal_outer',
- offsetRight: '40px',
toggle: onToggle
};
dispatch(openCustomContent('GIF_MODAL', customProps));
diff --git a/web/js/containers/gif.js b/web/js/containers/gif.js
index 3df42f224..d6edb39e9 100644
--- a/web/js/containers/gif.js
+++ b/web/js/containers/gif.js
@@ -2,6 +2,7 @@ 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 GifStream from '@entryline/gifstream';
import util from '../util/util';
import * as olProj from 'ol/proj';
import { debounce as lodashDebounce } from 'lodash';
@@ -16,32 +17,94 @@ import {
getPercentageFromPixel,
getPixelFromPercentage
} from '../modules/image-download/util';
-import { Modal, ModalHeader, ModalBody } from 'reactstrap';
+import { Progress } from 'reactstrap';
+import { timeScaleFromNumberKey } from '../modules/date/constants';
+import { getImageArray } from '../modules/animation/selectors';
+
+const gifStream = new GifStream();
class GIF extends Component {
constructor(props) {
super(props);
const screenHeight = props.screenHeight;
const screenWidth = props.screenWidth;
+ const boundaries = {
+ x: screenWidth / 2 - 100,
+ y: screenHeight / 2 - 100,
+ x2: screenWidth / 2 + 100,
+ y2: screenHeight / 2 + 100
+ };
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
+ boundaries
+ };
+ props.onChangeLocation(boundaries);
+ this.onBoundaryChange = this.onBoundaryChange.bind(this);
+ }
+ createGIF(width, height) {
+ const { getImageArray } = this.props;
+ var imageArra;
+ var stampWidth;
+ var build;
+ var stampProps;
+ var newImage;
+ var breakPointOne = 300;
+ var stampWidthRatio = 4.889;
+ build = function(stamp, dateStamp, stampHeight) {
+ imageArra = getImageArray(this.state, this.props, { width, height });
+ if (!imageArra) {
+ // won't be true if there are too mant frames
+ return;
}
+ gifStream.createGIF(
+ {
+ gifWidth: width,
+ gifHeight: height,
+ images: imageArra,
+ waterMarkXCoordinate: stampHeight * 0.01, // Margin based on GIF Height
+ waterMarkYCoordinate: stampHeight * 0.01, // Margin based on GIF Height
+ waterMarkHeight: stamp.height,
+ waterMark: stampHeight > 20 ? stamp : null,
+ waterMarkWidth: stamp.width,
+ fontSize: dateStamp.fontSize + 'px',
+ textXCoordinate: dateStamp.x,
+ textYCoordinate: dateStamp.y, // date location based on Dimensions
+ textAlign: dateStamp.align, // If textXCoordinate is null this takes precedence
+ textBaseline: 'top', // If textYCoordinate is null this takes precedence
+ fontColor: '#fff',
+ fontWeight: '300',
+ fontFamily: 'Open Sans, sans-serif',
+ progressCallback: onGifProgress,
+ showFrameText: stampHeight > 20,
+ extraLastFrameDelay: 1000,
+ text: '',
+ stroke: {
+ color: '#000',
+ pixels: dateStamp.fontSize * 0.05
+ },
+ pause: 1
+ },
+ onGifComplete
+ );
};
+ stampProps = getStampProps(stampWidthRatio, breakPointOne, stampWidth);
+ newImage = svgToPng(
+ 'brand/images/wv-logo-w-shadow.svg',
+ stampProps.stampHeight
+ );
+
+ build(newImage, stampProps.dateStamp, stampProps.stampHeight);
}
onBoundaryChange(boundaries) {
- const { screenWidth, screenHeight } = this.props;
+ const { screenWidth, screenHeight, onChangeLocation, width } = 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);
+ onChangeLocation({ x, y, x2, y2 });
this.setState({
boundaries: {
x: x,
@@ -55,21 +118,24 @@ class GIF extends Component {
const {
isActive,
increment,
- animationSpeed,
+ speed,
map,
screenWidth,
screenHeight,
proj,
- onClose
+ onClose,
+ endDate,
+ startDate
} = this.props;
const {
isDownloaded,
isDownloadError,
boundaries,
showDates,
- isValidSelection
+ isDownloading,
+ progress
} = this.state;
- console.log('yolo');
+
const { x, y, x2, y2 } = boundaries;
const isGeoProjection = proj.id === 'geographic';
const resolutions = isGeoProjection ? resolutionsGeo : resolutionsPolar;
@@ -87,17 +153,19 @@ class GIF extends Component {
);
if (!isActive) return '';
- // TODO if(isDownloaded) return <Down />
+ if (isDownloading) return <Progress now={progress} />;
return (
<Fragment>
<GifPanel
- speed={animationSpeed}
+ speed={speed}
resolutions={resolutions}
resolution={resolution}
showDates={showDates}
increment={increment}
projId={proj.id}
lonlats={lonlats}
+ startDate={startDate}
+ endDate={endDate}
/>
<Crop
@@ -107,7 +175,7 @@ class GIF extends Component {
maxWidth={screenWidth}
width={getPercentageFromPixel(screenWidth, x2 - x)}
height={getPercentageFromPixel(screenHeight, y2 - y)}
- onChange={lodashDebounce(this.onBoundaryChange.bind(this), 10)}
+ onChange={lodashDebounce(this.onBoundaryChange, 5)}
onClose={onClose}
coordinates={{
bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),
@@ -121,17 +189,37 @@ class GIF extends Component {
}
function mapStateToProps(state, ownProps) {
- const { isActive, onClose, increment } = ownProps;
- const { browser, proj, legacy, animation } = state;
+ const { browser, proj, legacy, animation, date, config } = state;
+ const { speed, startDate, endDate } = animation;
const { screenWidth, screenHeight } = browser;
+ const { customSelected, interval, customInterval, customDelta } = date;
+ let increment = customSelected
+ ? `${customDelta} ${timeScaleFromNumberKey[customInterval]}`
+ : `1 ${timeScaleFromNumberKey[interval]}`;
+ let url = 'http://localhost:3002/api/v1/snapshot';
+ if (config.features.imageDownload && config.features.imageDownload.url) {
+ url = config.features.imageDownload.url;
+ util.warn('Redirecting GIF download to: ' + url);
+ }
return {
- onClose,
screenWidth,
screenHeight,
proj: proj.selected,
isActive: true,
- increment,
+ startDate: startDate.toISOString(),
+ endDate: endDate.toISOString(),
+ increment: `${increment} Between Frames`,
+ speed,
map: legacy.map, // TODO replace with just map
+ url,
+ getImageArray: (gifComponentProps, gifComponentState, dimensions) => {
+ return getImageArray(
+ gifComponentProps,
+ gifComponentState,
+ dimensions,
+ state
+ );
+ },
onClose: () => {}
};
}
diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.js
index ba348502a..51440232b 100644
--- a/web/js/containers/image-download.js
+++ b/web/js/containers/image-download.js
@@ -4,7 +4,6 @@ import { connect } from 'react-redux';
import Panel from '../components/image-download/panel';
import Crop from '../components/util/image-crop';
import { onToggle } from '../modules/modal/actions';
-import { debounce } from 'lodash';
import ErrorBoundary from './error-boundary';
import * as olProj from 'ol/proj';
@@ -15,7 +14,7 @@ import {
getPixelFromPercentage
} from '../modules/image-download/util';
import util from '../util/util';
-
+import { getLayers } from '../modules/layers/selectors';
import {
resolutionsGeo,
resolutionsPolar,
@@ -63,7 +62,8 @@ class ImageDownloadContainer extends Component {
onClose,
models,
screenWidth,
- screenHeight
+ screenHeight,
+ date
} = this.props;
const { boundaries } = this.state;
const { x, y, x2, y2 } = boundaries;
@@ -91,7 +91,7 @@ class ImageDownloadContainer extends Component {
resolutions={resolutions}
lonlats={lonlats}
resolution={resolution}
- models={models}
+ date={date}
url={url}
crs={crs}
/>
@@ -102,7 +102,7 @@ class ImageDownloadContainer extends Component {
maxWidth={screenWidth}
width={getPercentageFromPixel(screenWidth, x2 - x)}
height={getPercentageFromPixel(screenHeight, y2 - y)}
- onChange={debounce(this.onBoundaryChange, 10)}
+ onChange={this.onBoundaryChange}
onClose={onClose}
bottomLeftStyle={{
left: x,
@@ -126,9 +126,10 @@ class ImageDownloadContainer extends Component {
}
function mapStateToProps(state) {
- const { config, models, proj, browser } = state;
+ const { config, proj, browser, layers, compare, date } = state;
const { screenWidth, screenHeight } = browser;
const { map } = state.legacy;
+ const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
let url = DEFAULT_URL;
if (config.features.imageDownload && config.features.imageDownload.url) {
url = config.features.imageDownload.url;
@@ -142,9 +143,19 @@ function mapStateToProps(state) {
proj,
url,
map,
- models,
screenWidth,
- screenHeight
+ screenHeight,
+ date: date[activeDateStr],
+ getLayers: () => {
+ return getLayers(
+ layers[compare.activeString],
+ {
+ reverse: true,
+ renderable: true
+ },
+ state
+ );
+ }
};
}
const mapDispatchToProps = dispatch => ({
diff --git a/web/js/containers/modal.js b/web/js/containers/modal.js
index 79567169a..a18b39388 100644
--- a/web/js/containers/modal.js
+++ b/web/js/containers/modal.js
@@ -9,13 +9,56 @@ import ErrorBoundary from './error-boundary';
import DetectOuterClick from '../components/util/detect-outer-click';
class ModalContainer extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ offsetTop: props.customProps.offsetTop,
+ offsetLeft: props.customProps.offsetLeft,
+ width: props.customProps.width
+ };
+ this.setOffsets = this.setOffsets.bind(this);
+ }
+ // static getDerivedStateFromProps(newProps, state) {
+ // const customProps = newProps.customProps;
+ // if (
+ // customProps.width !== state.width ||
+ // customProps.offsetLeft !== state.offsetLeft ||
+ // customProps.offsetRight !== state.offsetRight
+ // ) {
+ // return {
+ // width: customProps.width,
+ // offsetLeft: customProps.offsetLeft,
+ // offsetRight: customProps.offsetRight
+ // };
+ // } else return null;
+ // }
getStyle(props) {
return {
left: props.offsetLeft,
right: props.offsetRight,
- width: props.width
+ top: props.offsetTop,
+ maxWidth: props.width
};
}
+ setOffsets(boundaries) {
+ const { screenHeight, screenWidth, customProps } = this.props;
+ const { x, y, x2 } = boundaries;
+ const width = customProps.width;
+ const height = 280;
+ let left = x2 + 20;
+ let top = y - 20;
+ if (left + width > screenWidth && x - 20 - width > 0) {
+ left = x - 20 - width;
+ }
+ if (top + height > screenHeight) {
+ top = screenHeight - 20 - height;
+ }
+ this.setState({
+ offsetLeft: left,
+ offsetTop: top,
+ width
+ });
+ }
getTemplateBody() {
const { bodyTemplate } = this.props;
return bodyTemplate.isLoading ? (
@@ -48,9 +91,12 @@ class ModalContainer extends Component {
onClose,
CompletelyCustomModal,
bodyComponentProps,
- timeout
+ timeout,
+ dynamicOffsets
} = newProps;
- const style = this.getStyle(newProps);
+ const style = dynamicOffsets
+ ? this.getStyle(this.state)
+ : this.getStyle(newProps);
const lowerCaseId = lodashToLower(id);
const BodyComponent = bodyComponent || '';
const toggleWithClose = () => {
@@ -93,7 +139,10 @@ class ModalContainer extends Component {
<ModalBody>
{bodyHeader ? <h3>{bodyHeader}</h3> : ''}
{BodyComponent ? (
- <BodyComponent {...bodyComponentProps} />
+ <BodyComponent
+ {...bodyComponentProps}
+ onChangeLocation={this.setOffsets}
+ />
) : isTemplateModal ? (
this.getTemplateBody()
) : (
@@ -133,6 +182,8 @@ function mapStateToProps(state) {
isCustom,
id,
models,
+ screenWidth: state.browser.screenWidth,
+ screenHeight: state.browser.screenHeight,
bodyTemplate,
isTemplateModal,
customProps
@@ -148,7 +199,9 @@ export default connect(
mapStateToProps,
mapDispatchToProps
)(ModalContainer);
-
+ModalContainer.defaultProps = {
+ customProps: { width: 500, offsetTop: 0, offsetLeft: 0 }
+};
ModalContainer.propTypes = {
isCustom: PropTypes.bool,
id: PropTypes.string,
diff --git a/web/js/modules/animation/selectors.js b/web/js/modules/animation/selectors.js
new file mode 100644
index 000000000..f191726f9
--- /dev/null
+++ b/web/js/modules/animation/selectors.js
@@ -0,0 +1,132 @@
+import { each as lodashEach } from 'lodash';
+import util from '../../util/util';
+import {
+ imageUtilGetCoordsFromPixelValues,
+ imageUtilGetLayerOpacities,
+ bboxWMS13,
+ imageUtilGetLayers,
+ getDimensions
+} from '../image-download/util';
+import { getLayers } from '../layers/selectors';
+import { timeScaleFromNumberKey } from '../date/constants';
+/*
+ * loops through dates and created image
+ * download urls and pushs them to an
+ * array
+ *
+ * @method getImageArray
+ * @private
+ *
+ * @returns {array} array of jpg urls
+ *
+ */
+export function getImageArray(
+ gifComponentProps,
+ gifComponentState,
+ dimensions,
+ state
+) {
+ const { proj, map, animation, layers, compare } = state;
+ const { startDate, endDate, url } = gifComponentProps;
+ const { boundaries, showDates } = gifComponentState;
+ const {
+ customInterval,
+ interval,
+ customDelta,
+ delta,
+ customSelected
+ } = animation;
+ const activeString = compare.activeString;
+ var a = [];
+ var fromDate = new Date(startDate);
+ var toDate = new Date(endDate);
+ var current = fromDate;
+ var j = 0;
+ var src;
+ var strDate;
+ var lonlats = imageUtilGetCoordsFromPixelValues(boundaries, map.selected);
+ var layersArray;
+ var opacities;
+ let crs = proj.selected.crs;
+ let imgFormat = 'image/jpeg';
+ var products = getProducts(layers[activeString], fromDate, state);
+ var intervalAmount = customSelected ? customDelta : delta;
+ let increment = customSelected
+ ? timeScaleFromNumberKey[customInterval]
+ : timeScaleFromNumberKey[interval];
+ const height = dimensions.height;
+ const width = dimensions.width;
+ while (current <= toDate) {
+ j++;
+ if (state.date.maxZoom > 3) {
+ strDate = util.toISOStringSeconds(current);
+ } else {
+ strDate = util.toISOStringDate(current);
+ }
+ products = getProducts(layers[activeString], current, state);
+
+ layersArray = imageUtilGetLayers(products, proj.id);
+ opacities = imageUtilGetLayerOpacities(products);
+
+ let params = [
+ 'REQUEST=GetSnapshot',
+ `TIME=${util.toISOStringDate(current)}`,
+ `BBOX=${bboxWMS13(lonlats, crs)}`,
+ `CRS=${crs}`,
+ `LAYERS=${layersArray.join(',')}`,
+ `FORMAT=${imgFormat}`,
+ `WIDTH=${height}`,
+ `HEIGHT=${width}`
+ ];
+ if (opacities.length > 0) {
+ params.push(`OPACITIES=${opacities.join(',')}`);
+ }
+
+ let dlURL = url + '?' + params.join('&') + `&ts=${Date.now()}`;
+
+ src = util.format(dlURL, strDate);
+ a.push({
+ src: src,
+ text: showDates ? strDate : '',
+ delay: 1000 / interval
+ });
+ current = util.dateAdd(current, increment, intervalAmount);
+ if (j > 40) {
+ // too many frames
+ return false;
+ }
+ }
+ return a;
+}
+/*
+ * retrieves renderable layers
+ *
+ * @method getProducts
+ * @private
+ *
+ * @returns {array} array of layer objects
+ *
+ */
+var getProducts = function(layers, date, state) {
+ let layersArray = [];
+ var products = getLayers(
+ layers,
+ {
+ reverse: true,
+ renderable: true
+ },
+ state
+ );
+ lodashEach(products, function(layer) {
+ let layerDate = new Date(date);
+ if (layer.endDate) {
+ if (layerDate > new Date(layer.endDate)) return;
+ }
+ if (layer.visible && new Date(layer.startDate) <= layerDate) {
+ layersArray.push(layer);
+ } else if (!layer.startDate) {
+ layersArray.push(layer);
+ }
+ });
+ return layersArray;
+};