Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

#1908 hook up bounding box state to redux store so we can restore position when component is re-opened

Jason Kente1b36ea6fe1a
diff --git a/web/js/containers/gif.js b/web/js/containers/gif.js
index 282157687..c8e58b9a0 100644
--- a/web/js/containers/gif.js
+++ b/web/js/containers/gif.js
@@ -24,6 +24,7 @@ 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';
+import { changeCropBounds } from '../modules/animation/actions';
const gifStream = new GifStream();
@@ -32,7 +33,7 @@ class GIF extends Component {
super(props);
const screenHeight = props.screenHeight;
const screenWidth = props.screenWidth;
- const boundaries = {
+ const boundaries = props.boundaries || {
x: screenWidth / 2 - 100,
y: screenHeight / 2 - 100,
x2: screenWidth / 2 + 100,
@@ -84,7 +85,6 @@ class GIF extends Component {
numberOfFrames
} = this.props;
const { boundaries, showDates } = this.state;
-
const { x, y, x2, y2 } = boundaries;
const isGeoProjection = proj.id === 'geographic';
const resolutions = isGeoProjection ? resolutionsGeo : resolutionsPolar;
@@ -163,14 +163,14 @@ class GIF extends Component {
var breakPointOne = 300;
var stampWidthRatio = 4.889;
build = (stamp, dateStamp, stampHeight) => {
- let imageArra = getImageArray(this.state, this.props, { width, height });
- if (!imageArra) return; // won't be true if there are too mant frames
+ let imageArray = getImageArray(this.state, this.props, { width, height });
+ if (!imageArray) return; // won't be true if there are too many frames
gifStream.createGIF(
{
gifWidth: width,
gifHeight: height,
- images: imageArra,
+ images: imageArray,
waterMarkXCoordinate: stampHeight * 0.01, // Margin based on GIF Height
waterMarkYCoordinate: stampHeight * 0.01, // Margin based on GIF Height
waterMarkHeight: stamp.height,
@@ -251,13 +251,14 @@ class GIF extends Component {
});
}
onBoundaryChange(boundaries) {
- const { screenWidth, screenHeight } = this.props;
+ const { screenWidth, screenHeight, onBoundaryChange } = 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);
const width = 342;
const height = 280;
+ const bounds = { x, y, x2, y2 };
let left = x2 + 20;
let top = y - 20;
if (left + width > screenWidth && x - 20 - width > 0) {
@@ -266,15 +267,11 @@ class GIF extends Component {
if (top + height > screenHeight) {
top = screenHeight - 20 - height;
}
+ onBoundaryChange(bounds);
this.setState({
offsetLeft: left,
offsetTop: top,
- boundaries: {
- x: x,
- y: y,
- x2: x2,
- y2: y2
- }
+ boundaries: bounds
});
}
render() {
@@ -335,7 +332,7 @@ class GIF extends Component {
function mapStateToProps(state, ownProps) {
const { browser, proj, animation, map, date, config } = state;
- const { speed, startDate, endDate } = animation;
+ const { speed, startDate, endDate, boundaries } = animation;
const { screenWidth, screenHeight } = browser;
const { customSelected, interval, customInterval, customDelta } = date;
let increment = customSelected
@@ -349,6 +346,7 @@ function mapStateToProps(state, ownProps) {
return {
screenWidth,
screenHeight,
+ boundaries,
proj: proj.selected,
isActive: animation.gifActive,
startDate: startDate.toISOString(),
@@ -376,7 +374,11 @@ function mapStateToProps(state, ownProps) {
onClose: ownProps.onClose
};
}
-const mapDispatchToProps = dispatch => ({});
+const mapDispatchToProps = dispatch => ({
+ onBoundaryChange: (bounds) => {
+ dispatch(changeCropBounds(bounds));
+ }
+});
export default connect(
mapStateToProps,
@@ -384,12 +386,14 @@ export default connect(
)(GIF);
GIF.propTypes = {
+ boundaries: PropTypes.object,
endDate: PropTypes.string,
getImageArray: PropTypes.func,
increment: PropTypes.string,
isActive: PropTypes.bool,
map: PropTypes.object,
numberOfFrames: PropTypes.number,
+ onBoundaryChange: PropTypes.func,
onClose: PropTypes.func,
proj: PropTypes.object,
screenHeight: PropTypes.number,
diff --git a/web/js/modules/animation/actions.js b/web/js/modules/animation/actions.js
index f9b0fba42..c57d21852 100644
--- a/web/js/modules/animation/actions.js
+++ b/web/js/modules/animation/actions.js
@@ -8,6 +8,7 @@ import {
UPDATE_START_AND_END_DATE,
UPDATE_START_DATE,
UPDATE_END_DATE,
+ UPDATE_CROP_BOUNDS,
TOGGLE_GIF
} from './constants';
import util from '../../util/util';
@@ -80,6 +81,12 @@ export function changeEndDate(date) {
value: date
};
}
+export function changeCropBounds(bounds) {
+ return {
+ type: UPDATE_CROP_BOUNDS,
+ value: bounds
+ };
+}
export function toggleComponentGifActive() {
return {
type: TOGGLE_GIF
diff --git a/web/js/modules/animation/constants.js b/web/js/modules/animation/constants.js
index 2711a476a..90a30b17a 100644
--- a/web/js/modules/animation/constants.js
+++ b/web/js/modules/animation/constants.js
@@ -7,5 +7,6 @@ export const TOGGLE_LOOPING = 'ANIMATION/TOGGLE_LOOPING';
export const UPDATE_START_AND_END_DATE = 'ANIMATION/UPDATE_START_AND_END_DATE';
export const UPDATE_START_DATE = 'ANIMATION/UPDATE_START_DATE';
export const UPDATE_END_DATE = 'ANIMATION/UPDATE_END_DATE';
+export const UPDATE_CROP_BOUNDS = 'ANIMATION/UPDATE_CROP_BOUNDS';
export const TOGGLE_GIF = 'ANIMATION/TOGGLE_GIF';
export const KEY_PRESS_ACTION = 'ANIMATION/KEY_PRESS_ACTION';
diff --git a/web/js/modules/animation/reducers.js b/web/js/modules/animation/reducers.js
index 8b8fbf66d..f01104ba3 100644
--- a/web/js/modules/animation/reducers.js
+++ b/web/js/modules/animation/reducers.js
@@ -10,6 +10,7 @@ import {
UPDATE_START_AND_END_DATE,
UPDATE_START_DATE,
UPDATE_END_DATE,
+ UPDATE_CROP_BOUNDS,
TOGGLE_GIF,
KEY_PRESS_ACTION
} from './constants';
@@ -21,7 +22,8 @@ export const defaultState = {
speed: 3,
gifActive: false,
startDate: undefined,
- endDate: undefined
+ endDate: undefined,
+ boundares: undefined
};
export function getInitialState(config) {
return lodashAssign({}, defaultState, {
@@ -72,6 +74,10 @@ export function animationReducer(state = defaultState, action) {
endDate: action.value,
isPlaying: false
});
+ case UPDATE_CROP_BOUNDS:
+ return lodashAssign({}, state, {
+ boundaries: action.value
+ });
case TOGGLE_LOOPING:
return lodashAssign({}, state, {
loop: !state.loop