Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

redux image download #1576

Benjamin King27088b468046
diff --git a/web/css/modal.css b/web/css/modal.css
index c7bbfa96f..46578d8d4 100644
--- a/web/css/modal.css
+++ b/web/css/modal.css
@@ -7,7 +7,9 @@
.modal-dialog .close {
color: #fff;
}
-
+.clickable-behind-modal .modal {
+ position: inherit
+}
/* toolbar modal list styles */
.toolbar-list-modal,
.toolbar-list-modal .modal-content {
diff --git a/web/index.html b/web/index.html
index 6b3e13c71..80defae16 100644
--- a/web/index.html
+++ b/web/index.html
@@ -50,11 +50,6 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (http://opensource.gs
<body>
<div data-role="page" id="app">
</div>
- <div id="wv-tour-content" class="tour-content"></div>
- <div id="wv-image-top" class="wv-image-coords wv-image-top"></div>
- <div id="wv-image-right" class="wv-image-coords wv-image-right"></div>
- <div id="wv-image-bottom" class="wv-image-coords wv-image-bottom"></div>
- <div id="wv-image-left" class="wv-image-coords wv-image-left"></div>
<div class="backdrop"></div>
</body>
diff --git a/web/js/app.js b/web/js/app.js
index 2005dbebc..0f5f24c26 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -172,7 +172,7 @@ class App extends React.Component {
}
render() {
return (
- <div className="wv-content" data-role="content">
+ <div className="wv-content" id="wv-content" data-role="content">
<Toolbar />
<section id="wv-sidebar" />
<div id="layer-modal" className="layer-modal" />
diff --git a/web/js/components/image-download/grid.js b/web/js/components/image-download/grid.js
index d1a1b62f9..7ecda1b56 100644
--- a/web/js/components/image-download/grid.js
+++ b/web/js/components/image-download/grid.js
@@ -14,14 +14,17 @@ export default class ResolutionTable extends React.Component {
var size = this.props.fileSize;
if (!this.props.valid) {
return (
- <div id='wv-image-size' className='wv-image-size wv-image-size-invalid grid-child'>
- <i className='fa fa-times fa-fw' />
+ <div
+ id="wv-image-size"
+ className="wv-image-size wv-image-size-invalid grid-child"
+ >
+ <i className="fa fa-times fa-fw" />
<span>{'~' + size + 'MB'}</span>
</div>
);
} else {
return (
- <div id='wv-image-size' className='wv-image-size grid-child'>
+ <div id="wv-image-size" className="wv-image-size grid-child">
<span>{'~' + size + ' MB'} </span>
</div>
);
@@ -29,23 +32,39 @@ export default class ResolutionTable extends React.Component {
}
render() {
let imageSize = this.renderImageSize();
+ const { width, height, onClick, valid } = this.props;
return (
- <div className='wv-image-download-grid'>
- <div className='grid-child grid-head'><span>Raw Size</span></div>
- <div className='grid-child grid-head'><span>Maximum</span></div>
+ <div className="wv-image-download-grid">
+ <div className="grid-child grid-head">
+ <span>Raw Size</span>
+ </div>
+ <div className="grid-child grid-head">
+ <span>Maximum</span>
+ </div>
{imageSize}
- <div className={this.props.valid ? 'grid-child wv-image-max-size' : 'grid-child wv-image-max-size wv-image-size-invalid'} >
- <span>{ this.props.maxImageSize }</span>
+ <div
+ className={
+ this.props.valid
+ ? 'grid-child wv-image-max-size'
+ : 'grid-child wv-image-max-size wv-image-size-invalid'
+ }
+ >
+ <span>{this.props.maxImageSize}</span>
</div>
- <div className='grid-child wv-image-dimensions' id='wv-image-dimensions'>
- <span>{this.props.width + ' x ' + this.props.height + 'px' }</span>
+ <div
+ className="grid-child wv-image-dimensions"
+ id="wv-image-dimensions"
+ >
+ <span>{width + ' x ' + height + 'px'}</span>
</div>
- <div className='grid-child wv-image-button'>
+ <div className="grid-child wv-image-button">
<Button
- className='black'
- text='Download'
- onClick={this.props.onClick}
- valid={this.props.valid}
+ className="black"
+ text="Download"
+ onClick={() => {
+ onClick(width, height);
+ }}
+ valid={valid}
/>
</div>
</div>
diff --git a/web/js/components/image-download/panel.js b/web/js/components/image-download/panel.js
index 0b79e971d..64a1136ea 100644
--- a/web/js/components/image-download/panel.js
+++ b/web/js/components/image-download/panel.js
@@ -1,12 +1,16 @@
import React from 'react';
import {
imageSizeValid,
- getDimensions
+ getDimensions,
+ imageUtilGetLayers,
+ imageUtilGetLayerOpacities,
+ bboxWMS13
} from '../../modules/image-download/util';
import SelectionList from '../util/selector';
import ResTable from './grid';
import PropTypes from 'prop-types';
+import util from '../../util/util';
const MAX_DIMENSION_SIZE = 8200;
@@ -25,12 +29,50 @@ export default class ImageResSelection extends React.Component {
fileType: props.fileType,
fileSize: props.fileSize,
proj: this.props.proj,
- worldfile: props.worldfile,
+ isWorldfile: props.isWorldfile,
resolution: props.resolution,
- valid: props.valid
+ valid: props.valid,
+ debugUrl: ''
};
}
- onDownloadClick() {}
+ onDownload(imgWidth, imgHeight) {
+ const { models, url, lonlats, crs } = this.props;
+ const { fileType, isWorldfile } = this.state;
+ let time = new Date(models.date[models.date.activeDate].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 opacities = imageUtilGetLayerOpacities(layerList);
+
+ let params = [
+ 'REQUEST=GetSnapshot',
+ `TIME=${util.toISOStringDate(time)}`,
+ `BBOX=${bboxWMS13(lonlats, crs)}`,
+ `CRS=${crs}`,
+ `LAYERS=${layers.join(',')}`,
+ `FORMAT=${fileType}`,
+ `WIDTH=${imgWidth}`,
+ `HEIGHT=${imgHeight}`
+ ];
+ if (opacities.length > 0) {
+ params.push(`OPACITIES=${opacities.join(',')}`);
+ }
+ if (isWorldfile === true) {
+ params.push('WORLDFILE=true');
+ }
+ let dlURL = url + '?' + params.join('&') + `&ts=${Date.now()}`;
+ if (url) {
+ util.metrics('lc=' + encodeURIComponent(dlURL));
+ window.open(dlURL, '_blank');
+ } else {
+ console.log(url);
+ }
+ this.setState({ debugUrl: dlURL });
+ }
handleChange(type, value) {
if (type === 'resolution') {
this.setState({
@@ -38,7 +80,7 @@ export default class ImageResSelection extends React.Component {
});
} else if (type === 'worldfile') {
this.setState({
- worldfile: value
+ isWorldfile: value
});
} else {
this.setState({
@@ -73,7 +115,7 @@ export default class ImageResSelection extends React.Component {
) : (
<select
id="wv-image-worldfile"
- value={this.state.worldfile}
+ value={this.state.isWorldfile}
onChange={e => this.handleChange('worldfile', e.target.value)}
>
<option value={false}>No</option>
@@ -86,15 +128,21 @@ export default class ImageResSelection extends React.Component {
}
}
render() {
- const { projection, boundaries, resolutions, maxImageSize } = this.props;
- const { resolution } = this.state;
- const dimensions = getDimensions(projection, boundaries, resolution);
+ const { projection, lonlats, resolutions, maxImageSize } = this.props;
+ const { resolution, debugUrl } = this.state;
+ const dimensions = getDimensions(projection, lonlats, resolution);
const height = dimensions.height;
const width = dimensions.width;
const filetypeSelect = this._renderFileTypeSelect();
const worldfileSelect = this._renderWorldfileSelect();
+
return (
<div className="wv-re-pick-wrapper">
+ <div
+ id="wv-image-download-url"
+ style={{ display: 'none' }}
+ url={debugUrl}
+ />
<div className="wv-image-header">
<SelectionList
id="wv-image-resolution"
@@ -113,7 +161,7 @@ export default class ImageResSelection extends React.Component {
fileSize={((width * height * 24) / 8388608).toFixed(2)}
maxImageSize={maxImageSize}
valid={imageSizeValid(height, width, MAX_DIMENSION_SIZE)}
- onClick={this.onDownloadClick.bind(this)}
+ onClick={this.onDownload.bind(this)}
/>
</div>
);
@@ -127,7 +175,7 @@ ImageResSelection.defaultProps = {
height: '0',
imageSize: '0',
maxImageSize: '250 MB',
- worldfile: false,
+ isWorldfile: false,
resolution: '1',
worldFileOptions: true,
fileTypeOptions: true,
@@ -139,9 +187,9 @@ ImageResSelection.propTypes = {
fileTypes: PropTypes.object,
fileSize: PropTypes.string,
proj: PropTypes.string,
- worldfile: PropTypes.bool,
resolution: PropTypes.string,
valid: PropTypes.bool,
+ isWorldfile: PropTypes.bool,
onDownloadClick: PropTypes.func,
firstLabel: PropTypes.string,
maxImageSize: PropTypes.string,
diff --git a/web/js/components/util/image-crop.js b/web/js/components/util/image-crop.js
index 1f0abc0bb..f8e5f3e93 100644
--- a/web/js/components/util/image-crop.js
+++ b/web/js/components/util/image-crop.js
@@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
import Cropper from 'react-image-crop';
import { Portal } from 'react-portal';
+// https://stackoverflow.com/a/13139830
+const TRANSPARENT_GIF =
+ 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
/*
* A react reuseable list component
*
@@ -14,26 +17,70 @@ export default class Crop extends React.Component {
constructor(props) {
super(props);
this.state = {
- x: props.x,
- y: props.y,
- width: props.width,
- height: props.height
+ crop: {
+ x: props.x,
+ y: props.y,
+ width: props.width,
+ height: props.height
+ }
};
}
+ renderCoords() {
+ const { coordinates, topRightStyle, bottomLeftStyle } = this.props;
+ if (bottomLeftStyle.width < 50) {
+ return '';
+ }
+ return (
+ <React.Fragment>
+ <div
+ id="wv-image-top"
+ className="wv-image-coords wv-image-top"
+ style={topRightStyle}
+ >
+ {coordinates.topRight}
+ </div>
+ <div
+ id="wv-image-bottom"
+ className="wv-image-coords wv-image-bottom"
+ style={bottomLeftStyle}
+ >
+ {coordinates.bottomLeft}
+ </div>
+ </React.Fragment>
+ );
+ }
render() {
+ const {
+ onClose,
+ onChange,
+ maxWidth,
+ maxHeight,
+ showCoordinates
+ } = this.props;
+ const { crop } = this.state;
return (
- <Portal node={document && document.getElementById('wv-map')}>
+ <Portal node={document && document.getElementById('wv-content')}>
+ {showCoordinates ? this.renderCoords() : ''}
<Cropper
- crop={this.state}
- src={null}
+ crop={crop}
+ src={TRANSPARENT_GIF}
style={{
- width: '100%',
- height: '100%',
- position: 'absolute',
- background: 'none'
+ background:
+ crop.width && crop.height ? 'none' : 'rgba(0, 0, 0, 0.5)',
+ zIndex: 10
+ }}
+ imageStyle={{
+ width: maxWidth,
+ height: maxHeight
+ }}
+ onComplete={crop => {
+ if (!crop.width || !crop.height) {
+ onClose();
+ }
}}
onChange={crop => {
this.setState({ crop });
+ onChange(crop);
}}
/>
</Portal>
@@ -44,11 +91,15 @@ Crop.defaultProps = {
x: 20,
y: 10,
width: 30,
- height: 10
+ height: 10,
+ maxHeight: window.innerWidth,
+ maxWidth: window.innerHeight
};
Crop.propTypes = {
x: PropTypes.number,
y: PropTypes.number,
width: PropTypes.number,
- height: PropTypes.number
+ height: PropTypes.number,
+ onChange: PropTypes.func.isRequired,
+ onClose: PropTypes.func.isRequired
};
diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.js
index 2480e2487..3100f810d 100644
--- a/web/js/containers/image-download.js
+++ b/web/js/containers/image-download.js
@@ -3,7 +3,15 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import Panel from '../components/image-download/panel';
import Crop from '../components/util/image-crop';
-import { imageUtilCalculateResolution } from '../modules/image-download/util';
+import { debounce } from 'lodash';
+import * as olProj from 'ol/proj';
+
+import {
+ imageUtilCalculateResolution,
+ imageUtilGetCoordsFromPixelValues,
+ getPercentageFromPixel,
+ getPixelFromPercentage
+} from '../modules/image-download/util';
import util from '../util/util';
import {
@@ -20,72 +28,110 @@ class ImageDownloadContainer extends Component {
super(props);
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;
- const bounds = [
- [windowWidth / 2 - 100, windowHeight / 2 - 100],
- [windowWidth / 2 + 100, windowHeight / 2 + 100]
- ];
this.state = {
- boundaries: bounds
+ windowWidth: windowWidth,
+ windowHeight: windowHeight,
+ boundaries: {
+ x: windowWidth / 2 - 100,
+ y: windowHeight / 2 - 100,
+ x2: windowWidth / 2 + 100,
+ y2: windowHeight / 2 + 100
+ }
};
}
- // onDownload() {
- // let time = new Date(models.date[models.date.activeDate].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 opacities = imageUtilGetLayerOpacities(layerList);
- // let crs = models.proj.selected.crs;
-
- // let params = [
- // 'REQUEST=GetSnapshot',
- // `TIME=${util.toISOStringDate(time)}`,
- // `BBOX=${bboxWMS13(lonlats, crs)}`,
- // `CRS=${crs}`,
- // `LAYERS=${layers.join(',')}`,
- // `FORMAT=${imgFormat}`,
- // `WIDTH=${imgWidth}`,
- // `HEIGHT=${imgHeight}`
- // ];
- // if (opacities.length > 0) {
- // params.push(`OPACITIES=${opacities.join(',')}`);
- // }
- // if (imgWorldfile === 'true') {
- // params.push('WORLDFILE=true');
- // }
- // let dlURL = url + '?' + params.join('&') + `&ts=${Date.now()}`;
- // }
+ updateDimensions() {
+ const windowWidth = window.innerWidth;
+ const windowHeight = window.innerHeight;
+ this.setState({
+ windowWidth: windowWidth,
+ windowHeight: windowHeight
+ });
+ }
+ componentDidMount() {
+ window.addEventListener('resize', this.updateDimensions.bind(this));
+ }
+ componentWillUnmount() {
+ window.removeEventListener('resize', this.updateDimensions.bind(this));
+ }
+ onBoundaryChange(boundaries) {
+ const { windowWidth, windowHeight } = this.state;
+ const x = getPixelFromPercentage(windowWidth, boundaries.x);
+ const y = getPixelFromPercentage(windowHeight, boundaries.y);
+ const x2 = x + getPixelFromPercentage(windowWidth, boundaries.width);
+ const y2 = y + getPixelFromPercentage(windowHeight, boundaries.height);
+ this.setState({
+ boundaries: {
+ x: x,
+ y: y,
+ x2: x2,
+ y2: y2
+ }
+ });
+ }
render() {
- const { projection, models } = this.props;
- const { boundaries } = this.state;
+ const { projection, models, url, onClose } = this.props;
+ const { boundaries, windowWidth, windowHeight } = this.state;
+ const { x, y, x2, y2 } = boundaries;
const isGeoProjection = projection === 'geographic';
const fileTypes = isGeoProjection ? fileTypesGeo : fileTypesPolar;
const resolutions = isGeoProjection ? resolutionsGeo : resolutionsPolar;
- console.log(projection, isGeoProjection, models.proj.selected.resolutions);
+ const lonlats = imageUtilGetCoordsFromPixelValues(
+ boundaries,
+ models.map.selectedMap
+ );
+ const crs = models.proj.selected.crs;
+ const geolonlat1 = olProj.transform(lonlats[0], crs, 'EPSG:4326');
+ const geolonlat2 = olProj.transform(lonlats[1], crs, 'EPSG:4326');
+
const resolution = imageUtilCalculateResolution(
- models.map.zoom,
+ Math.round(models.map.getZoom()),
isGeoProjection,
models.proj.selected.resolutions
);
+
return (
<React.Fragment>
<Panel
projection={projection}
fileTypes={fileTypes}
resolutions={resolutions}
- boundaries={boundaries}
+ lonlats={lonlats}
resolution={resolution}
+ models={models}
+ url={url}
+ crs={crs}
+ />
+ <Crop
+ x={getPercentageFromPixel(windowWidth, x)}
+ y={getPercentageFromPixel(windowHeight, y)}
+ maxHeight={windowHeight}
+ maxWidth={windowWidth}
+ width={getPercentageFromPixel(windowWidth, x2 - x)}
+ height={getPercentageFromPixel(windowHeight, y2 - y)}
+ onChange={debounce(this.onBoundaryChange.bind(this), 10)}
+ onClose={onClose}
+ bottomLeftStyle={{
+ left: x,
+ top: y2 + 5,
+ width: x2 - x
+ }}
+ topRightStyle={{
+ left: x,
+ top: y - 20,
+ width: x2 - x
+ }}
+ coordinates={{
+ bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),
+ topRight: util.formatCoordinate([geolonlat2[0], geolonlat2[1]])
+ }}
+ showCoordinates={true}
/>
- <Crop />
</React.Fragment>
);
}
}
-function mapStateToProps(state) {
+function mapStateToProps(state, ownProps) {
const { id } = state.projection;
const { config, models } = state.models;
let url = DEFAULT_URL;
@@ -100,12 +146,16 @@ function mapStateToProps(state) {
return {
projection: id,
url,
- models
+ models,
+ onClose: ownProps.onClose
};
}
export default connect(mapStateToProps)(ImageDownloadContainer);
ImageDownloadContainer.propTypes = {
- projection: PropTypes.string
+ projection: PropTypes.string,
+ models: PropTypes.object.isRequired,
+ url: PropTypes.string.isRequired,
+ onClose: PropTypes.func.isRequired
};
diff --git a/web/js/containers/modal.js b/web/js/containers/modal.js
index db22903cd..cb7fff6b7 100644
--- a/web/js/containers/modal.js
+++ b/web/js/containers/modal.js
@@ -6,7 +6,6 @@ import { Modal, ModalBody, ModalHeader } from 'reactstrap';
import { customProps } from '../modules/modal/customs';
import { onToggle } from '../modules/modal/actions';
-import Crop from '../components/util/image-crop';
import DetectOuterClick from '../components/util/detect-outer-click';
class ModalContainer extends Component {
@@ -44,7 +43,8 @@ class ModalContainer extends Component {
modalClassName,
backdrop,
autoFocus,
- type
+ type,
+ wrapClassName
} = newProps;
const BodyComponent =
customProps[id] && customProps[id].bodyComponent
@@ -60,6 +60,7 @@ class ModalContainer extends Component {
className={modalClassName || 'default-modal'}
autoFocus={autoFocus || false}
style={style}
+ wrapClassName={wrapClassName}
>
<DetectOuterClick
onClick={onToggle}
@@ -75,7 +76,7 @@ class ModalContainer extends Component {
<ModalBody>
{bodyHeader ? <h3>{bodyHeader}</h3> : ''}
{BodyComponent ? (
- <BodyComponent />
+ <BodyComponent onClose={onToggle} />
) : isTemplateModal ? (
this.getTemplateBody()
) : (
diff --git a/web/js/map/model.js b/web/js/map/model.js
index 67e3185c1..44255cca5 100644
--- a/web/js/map/model.js
+++ b/web/js/map/model.js
@@ -6,7 +6,7 @@ export function mapModel(models, config) {
var self = {};
self.extent = null;
- self.zoom = null;
+ self.selectedMap = null;
self.events = util.events();
self.rotation = 0;
/*
@@ -24,8 +24,11 @@ export function mapModel(models, config) {
self.events.trigger('update', extent);
};
// Give other components access to zoom Level
- self.updateZoom = function(zoom) {
- self.zoom = Math.round(zoom);
+ self.updateMap = function(map) {
+ self.selectedMap = map;
+ };
+ self.getZoom = function() {
+ return self.selectedMap ? self.selectedMap.getView().getZoom() : null;
};
/*
* Sets map view from parsed URL
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 39394c92c..17dec215f 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -122,6 +122,7 @@ export function mapui(models, config) {
}
self.selected = self.proj[models.proj.selected.id];
var map = self.selected;
+ models.map.updateMap(map);
reloadLayers();
// Update the rotation buttons if polar projection to display correct value
@@ -906,7 +907,6 @@ export function mapui(models, config) {
var onZoomChange = function() {
var maxZoom = proj.resolutions.length;
var zoom = map.getView().getZoom();
- models.map.updateZoom(zoom);
if (zoom === 0) {
$zoomIn.button('enable');
$zoomOut.button('disable');
diff --git a/web/js/modules/image-download/util.js b/web/js/modules/image-download/util.js
index afbce2d77..d0d5950e6 100644
--- a/web/js/modules/image-download/util.js
+++ b/web/js/modules/image-download/util.js
@@ -186,3 +186,9 @@ export function getDimensions(projection, bounds, resolution) {
);
return { width: imgWidth, height: imgHeight };
}
+export function getPercentageFromPixel(maxDimension, dimension) {
+ return Math.round((dimension / maxDimension) * 100);
+}
+export function getPixelFromPercentage(maxDimension, percent) {
+ return Math.round((percent / 100) * maxDimension);
+}
diff --git a/web/js/modules/modal/customs.js b/web/js/modules/modal/customs.js
index 787bb69ed..43b69b822 100644
--- a/web/js/modules/modal/customs.js
+++ b/web/js/modules/modal/customs.js
@@ -31,6 +31,7 @@ export const customProps = {
TOOLBAR_SNAPSHOT: {
headerText: 'Take a Snapshot',
backdrop: false,
+ wrapClassName: 'clickable-behind-modal',
type: 'selection',
offsetRight: '70px',
modalClassName: 'toolbar-snapshot-modal toolbar-modal toolbar-medium-modal',