Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

gif-redux wip

Benjamin Kingaef7fc0c7083
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 6b2d56bbf..78b8523c6 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -6,5 +6,5 @@
"[json]": {
"editor.tabSize": 2
},
- "python.pythonPath": ".python\\Scripts\\python.exe"
+ "python.pythonPath": "/usr/local/opt/python@2/bin/python2.7"
}
\ No newline at end of file
diff --git a/web/js/components/animation-widget/gif-post-creation.js b/web/js/components/animation-widget/gif-post-creation.js
new file mode 100644
index 000000000..b9ee2b705
--- /dev/null
+++ b/web/js/components/animation-widget/gif-post-creation.js
@@ -0,0 +1,96 @@
+import React, { Component } from 'react';
+import PropTypes from 'prop-types';
+import { capitalize as lodashCapitalize } from 'lodash';
+import Button from '../util/button';
+import FileSaver from 'file-saver';
+import googleTagManager from 'googleTagManager';
+import util from '../../util/util';
+/*
+ * A table that updates with image
+ * data
+ *
+ * @class ResolutionTable
+ * @extends React.Component
+ */
+export class GifResults extends Component {
+ render() {
+ const { speed, startDate, endDate, increment, gifObject } = this.props;
+ const blob = gifObject.blob;
+ const size = gifObject.size;
+ const height = gifObject.height;
+ const blobURL = URL.createObjectURL(blob);
+ var dlURL = util.format(
+ 'nasa-worldview-{1}-to-{2}.gif',
+ startDate,
+ endDate
+ );
+
+ return (
+ <div className="gif-results-dialog-case clearfix">
+ <div
+ className="gif-results-dialog"
+ style={{ height: height, minHeight: 210 }}
+ >
+ <img src={blobURL} />
+ <div>
+ <div>
+ <b> Size: </b>
+ </div>
+ <div>{size} MB</div>
+ </div>
+ <div>
+ <div>
+ <b>Speed:</b>
+ </div>
+ <div>{speed} fps</div>
+ </div>
+ <div>
+ <div>
+ <b>Date Range:</b>
+ </div>
+ <div>{startDate}</div>
+ <div> - </div>
+ <div>{endDate} </div>
+ </div>
+ <div>
+ <div>
+ <b>Increments:</b>
+ </div>
+ <div> {lodashCapitalize(increment)} </div>
+ </div>
+ <Button
+ text="Download"
+ id="download-gif-button"
+ className="download wv-button"
+ onClick={e => {
+ e.stopPropagation();
+ e.preventDefault();
+ FileSaver.saveAs(blob, dlURL);
+ googleTagManager.pushEvent({
+ event: 'GIF_download',
+ GIF: {
+ downloadSize: size,
+ increments: increment,
+ frameSpeed: speed
+ }
+ });
+ }}
+ />
+ </div>
+ </div>
+ );
+ }
+}
+GifResults.propTypes = {
+ width: PropTypes.number,
+ height: PropTypes.number,
+ maxGifSize: PropTypes.number,
+ maxImageDimensionSize: PropTypes.number,
+ startDate: PropTypes.string,
+ endDate: PropTypes.string,
+ speed: PropTypes.number,
+ valid: PropTypes.bool,
+ requestSize: PropTypes.number,
+ fileSizeEstimate: PropTypes.number,
+ increment: PropTypes.string
+};
diff --git a/web/js/containers/gif.js b/web/js/containers/gif.js
index d6edb39e9..200771045 100644
--- a/web/js/containers/gif.js
+++ b/web/js/containers/gif.js
@@ -5,7 +5,7 @@ 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';
+import { debounce as lodashDebounce, round as lodashRound } from 'lodash';
import Crop from '../components/util/image-crop';
import {
resolutionsGeo,
@@ -19,7 +19,9 @@ import {
} from '../modules/image-download/util';
import { Progress } from 'reactstrap';
import { timeScaleFromNumberKey } from '../modules/date/constants';
+import { GifResults } from '../components/animation-widget/gif-post-creation';
import { getImageArray } from '../modules/animation/selectors';
+import { getStampProps, svgToPng } from '../modules/animation/util';
const gifStream = new GifStream();
@@ -39,22 +41,90 @@ class GIF extends Component {
isDownloadError: false,
showDates: true,
isValidSelection: true,
+ downloadedObject: {},
boundaries
};
props.onChangeLocation(boundaries);
this.onBoundaryChange = this.onBoundaryChange.bind(this);
+ this.onGifProgress = this.onGifProgress.bind(this);
+ }
+ renderSelectableBox() {
+ const {
+ increment,
+ speed,
+ map,
+ screenWidth,
+ screenHeight,
+ proj,
+ onClose,
+ endDate,
+ startDate
+ } = this.props;
+ const { boundaries, showDates } = this.state;
+
+ 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
+ );
+ return (
+ <Fragment>
+ <GifPanel
+ speed={speed}
+ resolutions={resolutions}
+ resolution={resolution}
+ showDates={showDates}
+ increment={increment}
+ projId={proj.id}
+ lonlats={lonlats}
+ startDate={startDate}
+ endDate={endDate}
+ onClick={this.createGIF.bind(this)}
+ />
+
+ <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, 5)}
+ onClose={onClose}
+ coordinates={{
+ bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),
+ topRight: util.formatCoordinate([geolonlat2[0], geolonlat2[1]])
+ }}
+ showCoordinates={false}
+ />
+ </Fragment>
+ );
}
createGIF(width, height) {
const { getImageArray } = this.props;
- var imageArra;
+ const { boundaries } = this.state;
+ const dimensions = {
+ w: boundaries.y2 - boundaries.y,
+ h: boundaries.x2 - boundaries.x
+ };
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 });
+ build = (stamp, dateStamp, stampHeight) => {
+ let imageArra = getImageArray(this.state, this.props, { width, height });
if (!imageArra) {
// won't be true if there are too mant frames
return;
@@ -77,7 +147,7 @@ class GIF extends Component {
fontColor: '#fff',
fontWeight: '300',
fontFamily: 'Open Sans, sans-serif',
- progressCallback: onGifProgress,
+ progressCallback: this.onGifProgress,
showFrameText: stampHeight > 20,
extraLastFrameDelay: 1000,
text: '',
@@ -87,19 +157,56 @@ class GIF extends Component {
},
pause: 1
},
- onGifComplete
+ obj => {
+ this.onGifComplete(obj, width, height);
+ }
);
};
- stampProps = getStampProps(stampWidthRatio, breakPointOne, stampWidth);
+ stampProps = getStampProps(
+ stampWidthRatio,
+ breakPointOne,
+ stampWidth,
+ dimensions,
+ width,
+ height
+ );
newImage = svgToPng(
'brand/images/wv-logo-w-shadow.svg',
stampProps.stampHeight
);
build(newImage, stampProps.dateStamp, stampProps.stampHeight);
+ this.setState({ isDownloading: true });
+ }
+ onGifComplete(obj, width, height) {
+ if (obj.error) {
+ this.setState({
+ isDownloadError: true,
+ isDownloading: false,
+ progress: 0,
+ downloadedObject: {}
+ });
+ } else {
+ this.setState({
+ isDownloaded: true,
+ progress: 0,
+ isDownloading: false,
+ downloadedObject: {
+ blob: obj.blob,
+ size: lodashRound((obj.blob.size / 1024) * 0.001, 2),
+ width,
+ height
+ }
+ });
+ }
+ }
+ onGifProgress(val) {
+ this.setState({
+ progress: val
+ });
}
onBoundaryChange(boundaries) {
- const { screenWidth, screenHeight, onChangeLocation, width } = this.props;
+ const { screenWidth, screenHeight, onChangeLocation } = this.props;
const x = getPixelFromPercentage(screenWidth, boundaries.x);
const y = getPixelFromPercentage(screenHeight, boundaries.y);
const x2 = x + getPixelFromPercentage(screenWidth, boundaries.width);
@@ -115,76 +222,28 @@ class GIF extends Component {
});
}
render() {
- const {
- isActive,
- increment,
- speed,
- map,
- screenWidth,
- screenHeight,
- proj,
- onClose,
- endDate,
- startDate
- } = this.props;
+ const { isActive, increment, speed, endDate, startDate } = this.props;
const {
isDownloaded,
- isDownloadError,
- boundaries,
- showDates,
isDownloading,
- progress
+ progress,
+ downloadedObject
} = this.state;
- 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 '';
- if (isDownloading) return <Progress now={progress} />;
- return (
- <Fragment>
- <GifPanel
+ if (isDownloading) return <Progress value={progress} />;
+ if (isDownloaded) {
+ return (
+ <GifResults
speed={speed}
- resolutions={resolutions}
- resolution={resolution}
- showDates={showDates}
- increment={increment}
- projId={proj.id}
- lonlats={lonlats}
+ gifObject={downloadedObject}
startDate={startDate}
endDate={endDate}
+ increment={increment}
/>
-
- <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, 5)}
- onClose={onClose}
- coordinates={{
- bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),
- topRight: util.formatCoordinate([geolonlat2[0], geolonlat2[1]])
- }}
- showCoordinates={false}
- />
- </Fragment>
- );
+ );
+ }
+ return this.renderSelectableBox();
}
}
@@ -210,7 +269,7 @@ function mapStateToProps(state, ownProps) {
endDate: endDate.toISOString(),
increment: `${increment} Between Frames`,
speed,
- map: legacy.map, // TODO replace with just map
+ map: legacy.map,
url,
getImageArray: (gifComponentProps, gifComponentState, dimensions) => {
return getImageArray(
diff --git a/web/js/modules/animation/selectors.js b/web/js/modules/animation/selectors.js
index f191726f9..4625af093 100644
--- a/web/js/modules/animation/selectors.js
+++ b/web/js/modules/animation/selectors.js
@@ -21,21 +21,15 @@ import { timeScaleFromNumberKey } from '../date/constants';
*
*/
export function getImageArray(
- gifComponentProps,
gifComponentState,
+ gifComponentProps,
dimensions,
state
) {
- const { proj, map, animation, layers, compare } = state;
+ const { proj, legacy, date, layers, compare } = state;
const { startDate, endDate, url } = gifComponentProps;
const { boundaries, showDates } = gifComponentState;
- const {
- customInterval,
- interval,
- customDelta,
- delta,
- customSelected
- } = animation;
+ const { customInterval, interval, customDelta, delta, customSelected } = date;
const activeString = compare.activeString;
var a = [];
var fromDate = new Date(startDate);
@@ -44,7 +38,10 @@ export function getImageArray(
var j = 0;
var src;
var strDate;
- var lonlats = imageUtilGetCoordsFromPixelValues(boundaries, map.selected);
+ var lonlats = imageUtilGetCoordsFromPixelValues(
+ boundaries,
+ legacy.map.selectedMap
+ );
var layersArray;
var opacities;
let crs = proj.selected.crs;
@@ -113,7 +110,8 @@ var getProducts = function(layers, date, state) {
layers,
{
reverse: true,
- renderable: true
+ renderable: true,
+ date
},
state
);
diff --git a/web/js/modules/animation/util.js b/web/js/modules/animation/util.js
index 2dd494d42..c8fbd6c1f 100644
--- a/web/js/modules/animation/util.js
+++ b/web/js/modules/animation/util.js
@@ -1,4 +1,9 @@
-import { cloneDeep as lodashCloneDeep, get } from 'lodash';
+import {
+ cloneDeep as lodashCloneDeep,
+ get,
+ round as lodashRound
+} from 'lodash';
+import canvg from 'canvg-browser';
export function getAnimationParameterSetup(
parameters,
@@ -96,3 +101,58 @@ export function getAnimationParameterSetup(
}
};
}
+export function getStampProps(
+ stampWidthRatio,
+ breakPoint,
+ stampWidth,
+ dimensions,
+ width,
+ height
+) {
+ var dateStamp = {};
+ var stampHeight;
+ var stampHeightByImageWidth;
+ // Set Logo-stamp dimensions based upon smallest total image dimension
+ if (dimensions.w < breakPoint) {
+ stampHeight =
+ (width * 0.7) / stampWidthRatio < 60
+ ? (width * 0.7) / stampWidthRatio
+ : 60;
+ dateStamp.fontSize =
+ dimensions.h > stampHeight * 1.5 ? lodashRound(stampHeight * 0.65) : 0;
+ dateStamp.align = 'left';
+ dateStamp.x = width * 0.01;
+ dateStamp.y = height - (dateStamp.fontSize + height * 0.01) - 4;
+ } else {
+ stampWidth = width * 0.4;
+ stampHeightByImageWidth = stampWidth / stampWidthRatio;
+ stampHeight =
+ stampHeightByImageWidth < 20
+ ? 20
+ : stampHeightByImageWidth > 60
+ ? 60
+ : stampHeightByImageWidth;
+ dateStamp.fontSize =
+ dimensions.h > stampHeight * 1.5 ? lodashRound(stampHeight * 0.65) : 0;
+ dateStamp.y = height - (dateStamp.fontSize + height * 0.01) - 4;
+ dateStamp.x = width * 0.01;
+ dateStamp.align = 'left';
+ }
+ return { stampHeight: stampHeight, dateStamp: dateStamp };
+}
+export function svgToPng(svgURL, stampHeight) {
+ var newImage;
+ var canvasEl = document.createElement('canvas');
+ var canvgOptions = {
+ log: false,
+ ignoreMouse: true,
+ scaleHeight: stampHeight
+ };
+ canvg(canvasEl, svgURL, canvgOptions);
+ newImage = new Image();
+ newImage.src = canvasEl.toDataURL('image/png');
+ newImage.width = canvasEl.width;
+ newImage.height = canvasEl.height;
+
+ return newImage;
+}
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.js
index bcd3bbc7e..c5012ecc4 100644
--- a/web/js/modules/layers/selectors.js
+++ b/web/js/modules/layers/selectors.js
@@ -12,6 +12,7 @@ import {
} from 'lodash';
import util from '../../util/util';
+import { compareAsc } from 'date-fns';
export function hasMeasurementSource(current, config, projId) {
var hasSource;
lodashValues(current.sources).forEach(function(source) {
@@ -199,7 +200,7 @@ function forGroup(group, spec, activeLayers, state) {
) {
return;
}
- if (spec.renderable && !isRenderable(def.id, activeLayers)) {
+ if (spec.renderable && !isRenderable(def.id, activeLayers, spec.date, state)) {
return;
}
if (spec.visible && !def.visible) {
@@ -361,6 +362,8 @@ function moveBefore(sourceId, targetId, layers) {
return layers;
}
export function isRenderable(id, activeLayers, date, state) {
+ const activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
+ date = date || state.date[activeDateStr];
var def = lodashFind(activeLayers, {
id: id
});