Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Retain image download state #1808

Benjamin King516c6f9f8800
diff --git a/web/js/components/image-download/panel.js b/web/js/components/image-download/panel.js
index 74ebbb996..ad5e0ed6d 100644
--- a/web/js/components/image-download/panel.js
+++ b/web/js/components/image-download/panel.js
@@ -81,6 +81,7 @@ export default class ImageResSelection extends React.Component {
this.setState({ debugUrl: dlURL });
}
handleChange(type, value) {
+ const { onPanelChange } = this.props;
if (type === 'resolution') {
this.setState({
resolution: value
@@ -94,6 +95,7 @@ export default class ImageResSelection extends React.Component {
fileType: value
});
}
+ onPanelChange(type, value);
}
_renderFileTypeSelect() {
if (this.props.fileTypeOptions) {
@@ -199,6 +201,7 @@ ImageResSelection.propTypes = {
isWorldfile: PropTypes.string,
lonlats: PropTypes.array,
maxImageSize: PropTypes.string,
+ onPanelChange: PropTypes.func,
projection: PropTypes.object,
resolution: PropTypes.string,
resolutions: PropTypes.object,
diff --git a/web/js/components/util/image-crop.js b/web/js/components/util/image-crop.js
index cf479eb32..7f8cbc291 100644
--- a/web/js/components/util/image-crop.js
+++ b/web/js/components/util/image-crop.js
@@ -64,6 +64,8 @@ export default class Crop extends React.Component {
<Cropper
crop={crop}
src={TRANSPARENT_GIF}
+ minWidth={2}
+ minHeight={2}
style={{
background:
crop.width && crop.height ? 'none' : 'rgba(0, 0, 0, 0.5)',
@@ -80,7 +82,9 @@ export default class Crop extends React.Component {
}}
onChange={crop => {
this.setState({ crop });
- onChange(crop);
+ if (crop.width && crop.height) {
+ onChange(crop);
+ }
}}
/>
</Portal>
diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.js
index 2082afc5d..7354d4af6 100644
--- a/web/js/containers/image-download.js
+++ b/web/js/containers/image-download.js
@@ -6,7 +6,7 @@ import Crop from '../components/util/image-crop';
import { onToggle } from '../modules/modal/actions';
import ErrorBoundary from './error-boundary';
import * as olProj from 'ol/proj';
-
+import { debounce as lodashDebounce } from 'lodash';
import {
imageUtilCalculateResolution,
imageUtilGetCoordsFromPixelValues,
@@ -21,6 +21,10 @@ import {
fileTypesGeo,
fileTypesPolar
} from '../modules/image-download/constants';
+import {
+ onPanelChange,
+ updateBoundaries
+} from '../modules/image-download/actions';
const DEFAULT_URL = 'http://localhost:3002/api/v1/snapshot';
@@ -29,14 +33,22 @@ class ImageDownloadContainer extends Component {
super(props);
const screenHeight = props.screenHeight;
const screenWidth = props.screenWidth;
+ const boundaryProps = props.boundaries;
this.state = {
+ fileType: props.fileType,
+ resolution: props.resolution,
+ isWorldfile: props.isWorldfile,
boundaries: {
- x: screenWidth / 2 - 100,
- y: screenHeight / 2 - 100,
- x2: screenWidth / 2 + 100,
- y2: screenHeight / 2 + 100
+ x: boundaryProps.x || screenWidth / 2 - 100,
+ y: boundaryProps.y || screenHeight / 2 - 100,
+ x2: boundaryProps.x2 || screenWidth / 2 + 100,
+ y2: boundaryProps.y2 || screenHeight / 2 + 100
}
};
+ this.debounceBoundaryUpdate = lodashDebounce(
+ this.props.onBoundaryChange,
+ 200
+ );
this.onBoundaryChange = this.onBoundaryChange.bind(this);
}
onBoundaryChange(boundaries) {
@@ -45,14 +57,17 @@ class ImageDownloadContainer extends Component {
const y = getPixelFromPercentage(screenHeight, boundaries.y);
const x2 = x + getPixelFromPercentage(screenWidth, boundaries.width);
const y2 = y + getPixelFromPercentage(screenHeight, boundaries.height);
+ const newBoundaries = {
+ x: x,
+ y: y,
+ x2: x2,
+ y2: y2
+ };
+
this.setState({
- boundaries: {
- x: x,
- y: y,
- x2: x2,
- y2: y2
- }
+ boundaries: newBoundaries
});
+ this.debounceBoundaryUpdate(newBoundaries);
}
render() {
const {
@@ -63,9 +78,10 @@ class ImageDownloadContainer extends Component {
screenWidth,
screenHeight,
date,
- getLayers
+ getLayers,
+ onPanelChange
} = this.props;
- const { boundaries } = this.state;
+ const { boundaries, resolution, isWorldfile, fileType } = this.state;
const { x, y, x2, y2 } = boundaries;
const isGeoProjection = proj.id === 'geographic';
const fileTypes = isGeoProjection ? fileTypesGeo : fileTypesPolar;
@@ -78,23 +94,28 @@ class ImageDownloadContainer extends Component {
const geolonlat1 = olProj.transform(lonlats[0], crs, 'EPSG:4326');
const geolonlat2 = olProj.transform(lonlats[1], crs, 'EPSG:4326');
- const resolution = imageUtilCalculateResolution(
- Math.round(map.ui.selected.getView().getZoom()),
- isGeoProjection,
- proj.selected.resolutions
- );
+ const newResolution =
+ resolution ||
+ imageUtilCalculateResolution(
+ Math.round(map.ui.selected.getView().getZoom()),
+ isGeoProjection,
+ proj.selected.resolutions
+ );
return (
<ErrorBoundary>
<Panel
projection={proj}
fileTypes={fileTypes}
+ fileType={fileType}
resolutions={resolutions}
lonlats={lonlats}
- resolution={resolution}
+ resolution={newResolution}
+ isWorldfile={isWorldfile}
date={date}
url={url}
crs={crs}
getLayers={getLayers}
+ onPanelChange={onPanelChange}
/>
<Crop
x={getPercentageFromPixel(screenWidth, x)}
@@ -127,7 +148,17 @@ class ImageDownloadContainer extends Component {
}
function mapStateToProps(state) {
- const { config, proj, browser, layers, compare, date, map } = state;
+ const {
+ config,
+ proj,
+ browser,
+ layers,
+ compare,
+ date,
+ map,
+ imageDownload
+ } = state;
+ const { isWorldfile, fileType, resolution, boundaries } = imageDownload;
const { screenWidth, screenHeight } = browser;
const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
let url = DEFAULT_URL;
@@ -145,6 +176,10 @@ function mapStateToProps(state) {
map,
screenWidth,
screenHeight,
+ isWorldfile,
+ fileType,
+ resolution,
+ boundaries,
date: date[activeDateStr],
getLayers: () => {
return getLayers(
@@ -161,6 +196,12 @@ function mapStateToProps(state) {
const mapDispatchToProps = dispatch => ({
onClose: () => {
dispatch(onToggle());
+ },
+ onPanelChange: (type, value) => {
+ dispatch(onPanelChange(type, value));
+ },
+ onBoundaryChange: obj => {
+ dispatch(updateBoundaries(obj));
}
});
@@ -169,13 +210,23 @@ export default connect(
mapDispatchToProps
)(ImageDownloadContainer);
+ImageDownloadContainer.defualtProps = {
+ fileType: 'image/jpeg'
+};
ImageDownloadContainer.propTypes = {
+ fileType: PropTypes.string.isRequired,
map: PropTypes.object.isRequired,
+ onBoundaryChange: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
+ onPanelChange: PropTypes.func.isRequired,
proj: PropTypes.object.isRequired,
url: PropTypes.string.isRequired,
+ boundaries: PropTypes.object,
date: PropTypes.object,
getLayers: PropTypes.func,
+ isWorldfile: PropTypes.bool,
+ resolution: PropTypes.string,
screenHeight: PropTypes.number,
- screenWidth: PropTypes.number
+ screenWidth: PropTypes.number,
+ worldfile: PropTypes.bool
};
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index 3349e1e16..804f25aed 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -30,9 +30,13 @@ import {
} from './date/reducers';
import { animationReducer } from './animation/reducers';
import { paletteReducer, getInitialPaletteState } from './palettes/reducers';
-import { vectorStyleReducer, getInitialVectorStyleState } from './vector-styles/reducers';
+import {
+ vectorStyleReducer,
+ getInitialVectorStyleState
+} from './vector-styles/reducers';
import dataDownloadReducer from './data/reducers';
import { get as lodashGet } from 'lodash';
+import { imageDownloadReducer } from './image-download/reducers';
function lastAction(state = null, action) {
return action;
@@ -105,6 +109,7 @@ const reducers = {
tour: tourReducer,
map: mapReducer,
animation: animationReducer,
+ imageDownload: imageDownloadReducer,
requestedEvents,
requestedEventSources,
requestedEventCategories,
diff --git a/web/js/modules/image-download/actions.js b/web/js/modules/image-download/actions.js
new file mode 100644
index 000000000..45f7a8e62
--- /dev/null
+++ b/web/js/modules/image-download/actions.js
@@ -0,0 +1,25 @@
+import {
+ UPDATE_BOUNDARIES,
+ UPDATE_FILE_TYPE,
+ UPDATE_RESOLUTION,
+ UPDATE_WORLDFILE
+} from './constants';
+
+export function updateBoundaries(obj) {
+ return {
+ type: UPDATE_BOUNDARIES,
+ boundaries: obj
+ };
+}
+export function onPanelChange(type, value) {
+ let actionType = UPDATE_FILE_TYPE;
+ if (type === 'resolution') {
+ actionType = UPDATE_RESOLUTION;
+ } else if (type === 'worldfile') {
+ actionType = UPDATE_WORLDFILE;
+ }
+ return {
+ type: actionType,
+ value: value
+ };
+}
diff --git a/web/js/modules/image-download/constants.js b/web/js/modules/image-download/constants.js
index a87b90046..e12824976 100644
--- a/web/js/modules/image-download/constants.js
+++ b/web/js/modules/image-download/constants.js
@@ -1,3 +1,8 @@
+export const UPDATE_BOUNDARIES = 'IMAGE-DOWNLOAD/UPDATE_BOUNDARIES';
+export const UPDATE_FILE_TYPE = 'IMAGE-DOWNLOAD/UPDATE_FILE_TYPE';
+export const UPDATE_WORLDFILE = 'IMAGE-DOWNLOAD/UPDATE_WORLDFILE';
+export const UPDATE_RESOLUTION = 'IMAGE-DOWNLOAD/UPDATE_RESOLUTION';
+
export const resolutionsGeo = {
values: [
{ value: '0.125', text: '30m' },
diff --git a/web/js/modules/image-download/reducers.js b/web/js/modules/image-download/reducers.js
new file mode 100644
index 000000000..af210297e
--- /dev/null
+++ b/web/js/modules/image-download/reducers.js
@@ -0,0 +1,36 @@
+import {
+ UPDATE_BOUNDARIES,
+ UPDATE_FILE_TYPE,
+ UPDATE_WORLDFILE,
+ UPDATE_RESOLUTION
+} from './constants';
+import { assign as lodashAssign } from 'lodash';
+export const defaultState = {
+ fileType: 'image/jpeg',
+ boundaries: {},
+ isWorldfile: false,
+ resolution: ''
+};
+
+export function imageDownloadReducer(state = defaultState, action) {
+ switch (action.type) {
+ case UPDATE_BOUNDARIES:
+ return lodashAssign({}, state, {
+ boundaries: action.boundaries
+ });
+ case UPDATE_FILE_TYPE:
+ return lodashAssign({}, state, {
+ fileType: action.value
+ });
+ case UPDATE_WORLDFILE:
+ return lodashAssign({}, state, {
+ isWorldfile: action.value
+ });
+ case UPDATE_RESOLUTION:
+ return lodashAssign({}, state, {
+ resolution: action.value
+ });
+ default:
+ return state;
+ }
+}