Interactive interface for browsing global, full-resolution satellite imagery
Add browser size redux lib #1576
Benjamin King9182237d0091
diff --git a/package-lock.json b/package-lock.jsonindex 06247211c..4d05935ee 100644--- a/package-lock.json+++ b/package-lock.json@@ -10799,6 +10799,11 @@"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=","dev": true},+ "mediaquery": {+ "version": "0.0.3",+ "resolved": "https://registry.npmjs.org/mediaquery/-/mediaquery-0.0.3.tgz",+ "integrity": "sha1-OH1hwQqpX/TWkH9qq90i16iY4D4="+ },"mem": {"version": "1.1.0","resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz",@@ -16968,6 +16973,14 @@"lodash.isplainobject": "4.0.6"}},+ "redux-responsive": {+ "version": "4.3.8",+ "resolved": "https://registry.npmjs.org/redux-responsive/-/redux-responsive-4.3.8.tgz",+ "integrity": "sha512-h+q9KTfaOdgXxFhqwHhAIHT/1ZiARFmM3iLMOnjpc79BUXlW24N3qJmUR5kOQYicIKKL0usIjNuNa+2HFTnxLg==",+ "requires": {+ "mediaquery": "0.0.3"+ }+ },"redux-thunk": {"version": "2.3.0","resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz",diff --git a/package.json b/package.jsonindex 3cfbf8bf0..06381df5d 100644--- a/package.json+++ b/package.json@@ -186,6 +186,7 @@"react-redux": "^6.0.0","reactstrap": "^7.0.0","redux": "^4.0.1",+ "redux-responsive": "^4.3.8","redux-thunk": "^2.3.0","simplebar": "3.0.0-beta.3","supercluster": "3.0.2",diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.jsindex 42fffbdd1..4cf96dfbe 100644--- a/web/js/containers/image-download.js+++ b/web/js/containers/image-download.js@@ -27,39 +27,23 @@ const DEFAULT_URL = 'http://localhost:3002/api/v1/snapshot';class ImageDownloadContainer extends Component {constructor(props) {super(props);- const windowWidth = window.innerWidth;- const windowHeight = window.innerHeight;+ const screenHeight = props.screenHeight;+ const screenWidth = props.screenWidth;this.state = {- windowWidth: windowWidth,- windowHeight: windowHeight,boundaries: {- x: windowWidth / 2 - 100,- y: windowHeight / 2 - 100,- x2: windowWidth / 2 + 100,- y2: windowHeight / 2 + 100+ x: screenWidth / 2 - 100,+ y: screenHeight / 2 - 100,+ x2: screenWidth / 2 + 100,+ y2: screenHeight / 2 + 100}};}- 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);+ const { screenWidth, screenHeight } = 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);this.setState({boundaries: {x: x,@@ -70,8 +54,16 @@ class ImageDownloadContainer extends Component {});}render() {- const { proj, map, url, onClose, models } = this.props;- const { boundaries, windowWidth, windowHeight } = this.state;+ const {+ proj,+ map,+ url,+ onClose,+ models,+ screenWidth,+ screenHeight+ } = this.props;+ const { boundaries } = this.state;const { x, y, x2, y2 } = boundaries;const isGeoProjection = proj.id === 'geographic';const fileTypes = isGeoProjection ? fileTypesGeo : fileTypesPolar;@@ -102,12 +94,12 @@ class ImageDownloadContainer extends Component {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)}+ x={getPercentageFromPixel(screenWidth, x)}+ y={getPercentageFromPixel(screenHeight, y)}+ maxHeight={screenHeight}+ maxWidth={screenWidth}+ width={getPercentageFromPixel(screenWidth, x2 - x)}+ height={getPercentageFromPixel(screenHeight, y2 - y)}onChange={debounce(this.onBoundaryChange.bind(this), 10)}onClose={onClose}bottomLeftStyle={{@@ -132,7 +124,8 @@ class ImageDownloadContainer extends Component {}function mapStateToProps(state) {- const { config, models, proj } = state;+ const { config, models, proj, browser } = state;+ const { screenWidth, screenHeight } = browser;const { map } = state.legacy;let url = DEFAULT_URL;if (config.features.imageDownload && config.features.imageDownload.url) {@@ -142,11 +135,14 @@ function mapStateToProps(state) {url = config.parameters.imageDownload;util.warn('Redirecting image download to: ' + url);}+return {proj,url,map,- models+ models,+ screenWidth,+ screenHeight};}const mapDispatchToProps = dispatch => ({@@ -165,5 +161,7 @@ ImageDownloadContainer.propTypes = {map: PropTypes.object.isRequired,models: PropTypes.object.isRequired,url: PropTypes.string.isRequired,- onClose: PropTypes.func.isRequired+ onClose: PropTypes.func.isRequired,+ screenWidth: PropTypes.number,+ screenHeight: PropTypes.number};diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.jsindex 1f5cb2f60..62f1709b7 100644--- a/web/js/modules/combine-reducers.js+++ b/web/js/modules/combine-reducers.js@@ -1,5 +1,6 @@import { combineReducers } from 'redux';import { modalReducer, modalAboutPage } from './modal/reducers';+import { createResponsiveStateReducer } from 'redux-responsive';import legacyReducer from './migration/reducers';import feedbackReducer from './feedback/reducers';import projectionReducer from './projection/reducer';@@ -19,6 +20,21 @@ export function getInitialState(models, config, parameters) {proj: getProjInitialState(config)};}+const responsiveStateReducer = createResponsiveStateReducer(+ {+ extraSmall: 500,+ small: 740,+ medium: 1000,+ large: 1280,+ extraLarge: 1400+ },+ {+ extraFields: () => ({+ screenWidth: window.innerWidth,+ screenHeight: window.innerHeight+ })+ }+);const defaultReducer = (state = {}) => state;const reducers = {proj: projectionReducer,@@ -30,6 +46,7 @@ const reducers = {config: defaultReducer,models: defaultReducer,parameters: defaultReducer,+ browser: responsiveStateReducer,modalAboutPage,shortLink,notificationsRequest