Interactive interface for browsing global, full-resolution satellite imagery
WV-2317: Add Ability To manually input image download extents (#3898)
Benjaki22ac07b23a041
diff --git a/e2e/features/image-download/global-select.js b/e2e/features/image-download/global-select.jsnew file mode 100644index 000000000..bf14ed18c--- /dev/null+++ b/e2e/features/image-download/global-select.js@@ -0,0 +1,41 @@+const { bookmark } = require('../../reuseables/bookmark');+const { normalizeViewport } = require('../../reuseables/normalize-viewport');+const {+ openImageDownloadPanel,+} = require('../../reuseables/image-download');++const startParams = [+ 'p=geographic',+ 'v=-180,-90,180,90',+ 'l=MODIS_Terra_CorrectedReflectance_TrueColor',+ 't=2018-06-01',+ 'imageDownload=',+];++const globalSelectInput = '#image-global-cb';+module.exports = {+ after(client) {+ client.end();+ },+ 'Verify that global select is present and not selected': function(c) {+ normalizeViewport(c, 1024, 768);+ bookmark(c, startParams);+ openImageDownloadPanel(c);+ c.expect.element(globalSelectInput).to.be.present;+ c.expect.element(globalSelectInput).to.not.be.selected;+ },+ 'Verify that checking checkbox updates bounding-box labels': function(c) {+ c.expect.element('#wv-image-top').text.to.not.contain('180.0000');+ c.click(globalSelectInput);+ c.expect.element('#wv-image-top').text.to.contain('180.0000');+ c.expect.element('#wv-image-bottom').text.to.contain('180.0000');+ c.pause(500);+ },+ 'Verify that unchecking checkbox updates bounding-box to previous': function(c) {+ c.click(globalSelectInput);+ c.expect.element('#wv-image-top').text.to.not.contain('180.0000');+ c.expect.element('#wv-image-top').text.to.contain('35.1563');+ c.expect.element('#wv-image-bottom').text.to.contain('35.1563');+ c.pause(2000);+ },+};diff --git a/e2e/features/image-download/lat-long-inputs-test.js b/e2e/features/image-download/lat-long-inputs-test.jsnew file mode 100644index 000000000..b43e9f910--- /dev/null+++ b/e2e/features/image-download/lat-long-inputs-test.js@@ -0,0 +1,57 @@+const { loadAndSkipTour } = require('../../reuseables/skip-tour');+const {+ openImageDownloadPanel,+} = require('../../reuseables/image-download');++const TIME_LIMIT = 5000;+const input = {+ maxLat: '#latlong-input-3',+ maxLon: '#latlong-input-2',+ minLat: '#latlong-input-1',+ minLon: '#latlong-input-0',+};++const changeInput = (c, selector, newValue) => {+ [...'123456'].forEach(() => {+ c.sendKeys(selector, c.Keys.ARROW_RIGHT);+ });+ [...'123456789'].forEach(() => {+ c.sendKeys(selector, c.Keys.BACK_SPACE);+ });+ c.sendKeys(selector, newValue);+ c.sendKeys(selector, c.Keys.ENTER);+};++module.exports = {+ before(client) {+ loadAndSkipTour(client, TIME_LIMIT);+ },++ after(client) {+ client.end();+ },++ 'Check that image download inputs are hidden on initial load': function(c) {+ openImageDownloadPanel(c);+ c.expect.element('.wv-image-input-title span').text.to.equal('Edit Coordinates');+ c.expect.element('.wv-image-input-subtitle').to.not.be.present;+ },+ 'Check that image download extent inputs open on click': function(c) {+ c.click('.wv-image-input-title span');+ c.waitForElementVisible('.wv-image-input-subtitle', TIME_LIMIT);+ },+ 'Verify that input updates crop boundary labels ': function(c) {+ c.waitForElementVisible(input.maxLat, TIME_LIMIT);++ changeInput(c, input.maxLat, '-14');+ changeInput(c, input.maxLon, '14');+ changeInput(c, input.minLat, '-40');+ changeInput(c, input.minLon, '-20');++ c.waitForElementVisible('#wv-image-top', TIME_LIMIT);+ c.assert.containsText('#wv-image-top', '-14.0000');+ c.assert.containsText('#wv-image-top', '14.0000');+ c.assert.containsText('#wv-image-bottom', '-40.0000');+ c.assert.containsText('#wv-image-bottom', '-20.0000');+ },+};diff --git a/e2e/reuseables/zoom.js b/e2e/reuseables/zoom.jsindex f66820190..28957d120 100644--- a/e2e/reuseables/zoom.js+++ b/e2e/reuseables/zoom.js@@ -3,4 +3,8 @@ module.exports = {c.click('button.wv-map-zoom-in');c.pause(300);},+ zoomOut(c) {+ c.click('button.wv-map-zoom-out');+ c.pause(300);+ },};diff --git a/package-lock.json b/package-lock.jsonindex 1fb6d5189..9ecce298b 100644--- a/package-lock.json+++ b/package-lock.json@@ -49,7 +49,7 @@"react-contextmenu": "^2.14.0","react-dom": "^16.12.0","react-draggable": "^4.1.0",- "react-image-crop": "^8.5.0",+ "react-image-crop": "^9.1.1","react-infinite-scroller": "^1.2.4","react-joyride": "^2.3.0","react-masonry-component": "^6.2.1",@@ -22085,12 +22085,11 @@}},"node_modules/react-image-crop": {- "version": "8.6.12",- "resolved": "https://registry.npmjs.org/react-image-crop/-/react-image-crop-8.6.12.tgz",- "integrity": "sha512-3CNz1xfsRRSH/iH023IDMXxzsb1M6RTHHUVsVcb8uFPcjGiA9WisvQ24G1eRDf2j4NlybupOEEdfK2vT0etN6A==",+ "version": "9.1.1",+ "resolved": "https://registry.npmjs.org/react-image-crop/-/react-image-crop-9.1.1.tgz",+ "integrity": "sha512-n7O3Cn7RuZJF8ooau2atwCGWZHqO7akl/pa6IR+1jWy5X0x4enTOCWOeswYhcBOv0ohmDHctAlf6mcUuSSwsow==","dependencies": {- "clsx": "^1.1.1",- "prop-types": "^15.7.2"+ "clsx": "^1.1.1"},"peerDependencies": {"react": ">=16.13.1"@@ -47058,12 +47057,11 @@}},"react-image-crop": {- "version": "8.6.12",- "resolved": "https://registry.npmjs.org/react-image-crop/-/react-image-crop-8.6.12.tgz",- "integrity": "sha512-3CNz1xfsRRSH/iH023IDMXxzsb1M6RTHHUVsVcb8uFPcjGiA9WisvQ24G1eRDf2j4NlybupOEEdfK2vT0etN6A==",+ "version": "9.1.1",+ "resolved": "https://registry.npmjs.org/react-image-crop/-/react-image-crop-9.1.1.tgz",+ "integrity": "sha512-n7O3Cn7RuZJF8ooau2atwCGWZHqO7akl/pa6IR+1jWy5X0x4enTOCWOeswYhcBOv0ohmDHctAlf6mcUuSSwsow==","requires": {- "clsx": "^1.1.1",- "prop-types": "^15.7.2"+ "clsx": "^1.1.1"}},"react-infinite-scroller": {@@ -53447,4 +53445,4 @@"dev": true}}-}\ No newline at end of file+}diff --git a/package.json b/package.jsonindex 8e1ec4718..0c025ae1d 100644--- a/package.json+++ b/package.json@@ -203,7 +203,7 @@"react-contextmenu": "^2.14.0","react-dom": "^16.12.0","react-draggable": "^4.1.0",- "react-image-crop": "^8.5.0",+ "react-image-crop": "^9.1.1","react-infinite-scroller": "^1.2.4","react-joyride": "^2.3.0","react-masonry-component": "^6.2.1",diff --git a/web/js/components/dateline/datelines.js b/web/js/components/dateline/datelines.jsindex 07ba5dbec..4932285aa 100644--- a/web/js/components/dateline/datelines.js+++ b/web/js/components/dateline/datelines.js@@ -8,7 +8,7 @@ import { getSelectedDate } from '../../modules/date/selectors';function DateLines(props) {const {- map, proj, date, isCompareActive, mapIsRendered, alwaysShow,+ map, proj, date, isCompareActive, mapIsRendered, alwaysShow, hideText,} = props;if (!mapIsRendered) return null;@@ -71,6 +71,7 @@ function DateLines(props) {<Lineid="dateline-left"map={map}+ hideText={hideText}alwaysShow={alwaysShow}isCompareActive={isCompareActive}height={hideLines ? 0 : height}@@ -83,6 +84,7 @@ function DateLines(props) {<Lineid="dateline-right"map={map}+ hideText={hideText}alwaysShow={alwaysShow}isCompareActive={isCompareActive}height={hideLines ? 0 : height}@@ -98,15 +100,17 @@ function DateLines(props) {const mapStateToProps = (state) => {const {- proj, map, compare, settings,+ proj, map, compare, settings, modal,} = state;+ const isImageDownload = modal.id === 'TOOLBAR_SNAPSHOT' && modal.isOpen;return {proj,map: map.ui.selected,date: getSelectedDate(state),isCompareActive: compare.active,mapIsRendered: map.rendered,- alwaysShow: settings.alwaysShowDatelines,+ hideText: isImageDownload,+ alwaysShow: isImageDownload || settings.alwaysShowDatelines,};};@@ -117,6 +121,7 @@ DateLines.propTypes = {isCompareActive: PropTypes.bool,mapIsRendered: PropTypes.bool,alwaysShow: PropTypes.bool,+ hideText: PropTypes.bool,};export default connect(diff --git a/web/js/components/dateline/line.js b/web/js/components/dateline/line.jsindex bd9292f37..dcf92747f 100644--- a/web/js/components/dateline/line.js+++ b/web/js/components/dateline/line.js@@ -82,6 +82,7 @@ class Line extends React.Component {map,height,textCoords,+ hideText,} = this.props;const { hovered, textActive } = this.state;@@ -130,7 +131,7 @@ class Line extends React.Component {/></svg><LineText- active={alwaysShow || textActive}+ active={!hideText && (alwaysShow || textActive)}map={map}date={date}x={lineX}@@ -156,6 +157,7 @@ Line.propTypes = {style: PropTypes.object,setTextCoords: PropTypes.func,textCoords: PropTypes.array,+ hideText: PropTypes.bool,};export default Line;diff --git a/web/js/components/image-download/global-select.js b/web/js/components/image-download/global-select.jsnew file mode 100644index 000000000..6ad8f17a3--- /dev/null+++ b/web/js/components/image-download/global-select.js@@ -0,0 +1,50 @@+import React, { useState } from 'react';+import PropTypes from 'prop-types';+import { isEqual } from 'lodash';+import Checkbox from '../util/checkbox';++const GLOBAL_LAT_LONG_EXTENT = [-180, -90, 180, 90];++const GlobalSelectCheckbox = (props) => {+ const {+ onLatLongChange, geoLatLong, proj, map,+ } = props;++ const boundingBoxArray = [...geoLatLong[0], ...geoLatLong[1]];+ const globalSelected = isEqual(boundingBoxArray, GLOBAL_LAT_LONG_EXTENT);+ const [prevExtent, setPrevExtent] = useState(globalSelected ? [-40, -40, 40, 40] : boundingBoxArray);+ const onCheck = () => {+ const useExtent = globalSelected ? prevExtent : GLOBAL_LAT_LONG_EXTENT;+ setPrevExtent(boundingBoxArray);+ map.getView().setCenter([0, 0]);+ map.getView().setZoom(0);+ setTimeout(() => {+ onLatLongChange(useExtent);+ }, 50);+ };++ const globalIsNotSelected = GLOBAL_LAT_LONG_EXTENT.some((latLongValue, index) => latLongValue !== boundingBoxArray[index]);+ if (proj !== 'geographic') return null;++ return (+ <div className="p-1">+ <Checkbox+ onCheck={onCheck}+ checked={!globalIsNotSelected}+ id="image-global-cb"+ label="Select Entire Globe"+ classNames="image-gb-checkbox"+ tooltipPlacement="top"+ />+ </div>+ );+};+GlobalSelectCheckbox.propTypes = {+ onLatLongChange: PropTypes.func,+ geoLatLong: PropTypes.array,+ proj: PropTypes.string,+ map: PropTypes.object,+};++export default GlobalSelectCheckbox;+diff --git a/web/js/components/image-download/panel.js b/web/js/components/image-download/image-download-panel.jssimilarity index 86%rename from web/js/components/image-download/panel.jsrename to web/js/components/image-download/image-download-panel.jsindex e93124703..42821aa50 100644--- a/web/js/components/image-download/panel.js+++ b/web/js/components/image-download/image-download-panel.js@@ -9,6 +9,8 @@ import {import SelectionList from '../util/selector';import ResTable from './grid';import AlertUtil from '../util/alert';+import LatLongSelect from './lat-long-inputs';+import GlobalSelectCheckbox from './global-select';const MAX_DIMENSION_SIZE = 8200;const RESOLUTION_KEY = {@@ -28,7 +30,7 @@ const RESOLUTION_KEY = {* @class resolutionSelection* @extends React.Component*/-export default class ImageResSelection extends React.Component {+export default class ImageDownloadPanel extends React.Component {constructor(props) {super(props);@@ -160,8 +162,9 @@ export default class ImageResSelection extends React.Component {render() {const {- getLayers, projection, lonlats, resolutions, maxImageSize, firstLabel,+ map, getLayers, viewExtent, projection, lonlats, resolutions, maxImageSize, firstLabel, geoLatLong, onLatLongChange,} = this.props;+ const { crs } = projection.selected;const { resolution, debugUrl } = this.state;const dimensions = getDimensions(projection.id, lonlats, resolution);const { height } = dimensions;@@ -191,6 +194,19 @@ export default class ImageResSelection extends React.Component {</div>{filetypeSelect}{worldfileSelect}+ <LatLongSelect+ viewExtent={viewExtent}+ geoLatLong={projection.id === 'geographic' ? lonlats : geoLatLong}+ onLatLongChange={onLatLongChange}+ crs={crs}+ />+ <GlobalSelectCheckbox+ viewExtent={viewExtent}+ geoLatLong={geoLatLong}+ onLatLongChange={onLatLongChange}+ proj={projection.id}+ map={map}+ /><ResTablewidth={width}height={height}@@ -206,7 +222,7 @@ export default class ImageResSelection extends React.Component {}}-ImageResSelection.defaultProps = {+ImageDownloadPanel.defaultProps = {fileType: 'image/jpeg',fileTypeOptions: true,firstLabel: 'Resolution (per pixel)',@@ -216,7 +232,8 @@ ImageResSelection.defaultProps = {secondLabel: 'Format',worldFileOptions: true,};-ImageResSelection.propTypes = {++ImageDownloadPanel.propTypes = {date: PropTypes.object,datelineMessage: PropTypes.string,fileType: PropTypes.string,@@ -226,6 +243,7 @@ ImageResSelection.propTypes = {getLayers: PropTypes.func,isWorldfile: PropTypes.bool,lonlats: PropTypes.array,+ map: PropTypes.object,maxImageSize: PropTypes.string,markerCoordinates: PropTypes.array,onPanelChange: PropTypes.func,@@ -234,5 +252,8 @@ ImageResSelection.propTypes = {resolutions: PropTypes.object,secondLabel: PropTypes.string,url: PropTypes.string,+ viewExtent: PropTypes.array,worldFileOptions: PropTypes.bool,+ geoLatLong: PropTypes.array,+ onLatLongChange: PropTypes.func,};diff --git a/web/js/components/image-download/lat-long-inputs.js b/web/js/components/image-download/lat-long-inputs.jsnew file mode 100644index 000000000..c8694b753--- /dev/null+++ b/web/js/components/image-download/lat-long-inputs.js@@ -0,0 +1,186 @@+import React, { useState, useEffect } from 'react';+import * as olProj from 'ol/proj';+import {+ clone as lodashClone,+} from 'lodash';+import { containsExtent, isEmpty } from 'ol/extent';+import PropTypes from 'prop-types';+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';+++const isValidExtent = (extent) => {+ if (extent.length !== 4) return false;+ if (extent.some((number) => Number.isNaN(number))) return false;+ return true;+};++const Input = ({+ index, title, boundingBoxArray, onLatLongChange, inputNumber, viewExtent, crs,+}) => {+ const [inputValue, setInputValue] = useState(inputNumber);+ const [isInvalid, setInputInvalid] = useState(false);++ useEffect(() => {+ setInputValue(inputNumber);+ }, [inputNumber]);++ const update = () => {+ try {+ const newInputValue = Number(inputValue);+ const newArray = lodashClone(boundingBoxArray);+ newArray[index] = newInputValue;+ const crsCorrectedExtent = olProj.transformExtent(newArray, 'EPSG:4326', crs);++ if (containsExtent(viewExtent, crsCorrectedExtent)+ && isValidExtent(newArray)+ && !isEmpty(crsCorrectedExtent)+ && !Number.isNaN(newInputValue)) {+ onLatLongChange(newArray);+ setInputInvalid(false);+ } else {+ setInputValue(boundingBoxArray[index].toFixed(4));+ setInputInvalid(true);+ setTimeout(() => setInputInvalid(false), 4000);+ }+ } catch (e) {+ console.warn(e);+ setInputValue(boundingBoxArray[index].toFixed(4));+ setInputInvalid(true);+ setTimeout(() => setInputInvalid(false), 4000);+ }+ };++ /**+ * onKeyUp determine if the input if valid and+ * send new value to parent+ * @param {Object} e Event Object+ */+ const onKeyDown = (e) => {+ const { keyCode } = e;+ const entered = Number(keyCode) === 13;+ const tabbed = Number(keyCode) === 9;+ if (entered || tabbed) {+ update();+ }+ };++ return (+ <div className="field col-12 col-sm-6">+ <label htmlFor={`latlong-input-${index}`} className="wv-image-label-lat-lon w-100">{title}</label>+ <input+ type="text"+ onKeyDown={onKeyDown}+ name="min-latitude"+ id={`latlong-input-${index}`}+ className="input input-lat-long w-100"+ required+ value={inputValue}+ onBlur={update}+ onChange={(e) => setInputValue(e.target.value)}+ />+ {isInvalid && (<span className="red-font invalid">Not Visible</span>)}+ </div>+ );+};++const LatLongSelect = (props) => {+ const {+ onLatLongChange, geoLatLong, viewExtent, crs,+ } = props;+ const boundingBoxArray = [geoLatLong[0][0], geoLatLong[0][1], geoLatLong[1][0], geoLatLong[1][1]];+ const [showCoordinates, setShowCoordinates] = useState(false);+ const coordText = showCoordinates ? 'Hide Coordinates' : 'Edit Coordinates';+ const [minLon, minLat, maxLon, maxLat] = boundingBoxArray.map((coord) => coord.toFixed(4).toString());++ return (+ <div className="wv-image-input-case">+ <div className="wv-image-input-title" onClick={() => { setShowCoordinates(!showCoordinates); }}>+ <span>{coordText}</span>+ <span+ title="Hide coordinates"+ className="wv-image-collapse-latlong"+ >+ <FontAwesomeIcon icon="caret-right" size="lg" rotation={showCoordinates ? 90 : 0} />+ </span>+ </div>+ {showCoordinates && (+ <>+ <div className="row">+ <div className="col-12">+ <h4 className="wv-image-input-subtitle">Top Right</h4>+ <div className="field-group field-group-bounding-box-top-right">+ <div className="row">+ <Input+ crs={crs}+ viewExtent={viewExtent}+ inputNumber={maxLat}+ boundingBoxArray={boundingBoxArray}+ onLatLongChange={onLatLongChange}+ index={3}+ title="max Latitude"+ />+ <Input+ crs={crs}+ viewExtent={viewExtent}+ inputNumber={maxLon}+ boundingBoxArray={boundingBoxArray}+ onLatLongChange={onLatLongChange}+ index={2}+ title="max Longitude"+ />+ </div>+ </div>+ </div>+ </div>+ <div className="row">+ <div className="col-12">+ <p className="wv-image-input-subtitle">Bottom Left</p>+ <div className="field-group field-group-bounding-box-bottom-left">+ <div className="row">+ <Input+ crs={crs}+ viewExtent={viewExtent}+ inputNumber={minLat}+ boundingBoxArray={boundingBoxArray}+ onLatLongChange={onLatLongChange}+ index={1}+ title="min Latitude"+ />+ <Input+ crs={crs}+ viewExtent={viewExtent}+ inputNumber={minLon}+ boundingBoxArray={boundingBoxArray}+ onLatLongChange={onLatLongChange}+ index={0}+ title="min Longitude"+ />+ </div>+ </div>+ </div>+ </div>+ </>+ )}+ </div>+ );+};+export default LatLongSelect;++const {+ number, array, func, string,+} = PropTypes;+LatLongSelect.propTypes = {+ onLatLongChange: func,+ geoLatLong: array,+ viewExtent: array,+ crs: string,+};+Input.propTypes = {+ onLatLongChange: func,+ index: number,+ title: string,+ boundingBoxArray: array,+ inputNumber: string,+ viewExtent: array,+ crs: string,+};diff --git a/web/js/components/util/checkbox.js b/web/js/components/util/checkbox.jsindex 41f4bd6bd..8f4efe42e 100644--- a/web/js/components/util/checkbox.js+++ b/web/js/components/util/checkbox.js@@ -1,6 +1,6 @@import React from 'react';import PropTypes from 'prop-types';-+import HoverTooltip from './hover-tooltip';/** A checkbox component* @class Checkbox@@ -8,31 +8,39 @@ import PropTypes from 'prop-types';*/export default function Checkbox (props) {const {- onCheck, checked, isRound, color, classNames, id, name, title, label, children,+ onCheck, checked, isRound, color, tooltipPlacement, classNames, id, name, title, label, children, disabled,} = props;const roundClassName = isRound ? 'wv-checkbox-round ' : '';const defaultClassName = 'wv-checkbox ';const checkedClassName = checked ? 'checked ' : '';- const caseClassName = defaultClassName + roundClassName + checkedClassName + color;-+ const disabledClassName = disabled ? ' disabled' : '';+ const caseClassName = defaultClassName + roundClassName + checkedClassName + color + disabledClassName;+ const showDisabledToolTip = disabled && id && title;return (- <div className={caseClassName}>- <input- type="checkbox"- id={id}- title={title}- name={name}- checked={checked}- className={classNames}- onChange={onCheck}- tabIndex="0"- />- {children}- <label htmlFor={id}>- <span>{label}</span>- </label>- </div>+ <>+ {showDisabledToolTip && (+ <>+ <HoverTooltip target={`#${id}-case`} labelText={title} placement={tooltipPlacement} />+ </>+ )}+ <div id={`${id}-case`} className={caseClassName}>+ <input+ type="checkbox"+ id={id}+ title={showDisabledToolTip ? '' : title}+ name={name}+ checked={checked}+ className={classNames}+ onChange={showDisabledToolTip ? () => null : onCheck}+ tabIndex="0"+ />+ {children}+ <label htmlFor={id}>+ <span>{label}</span>+ </label>+ </div>+ </>);}Checkbox.defaultProps = {@@ -40,12 +48,16 @@ Checkbox.defaultProps = {color: '',isRound: false,onCheck: null,+ disabled: false,+ tooltipPlacement: 'bottom',};Checkbox.propTypes = {checked: PropTypes.bool,children: PropTypes.node,classNames: PropTypes.string,+ disabled: PropTypes.bool,+ tooltipPlacement: PropTypes.string,color: PropTypes.string,id: PropTypes.string.isRequired,isRound: PropTypes.bool,diff --git a/web/js/components/util/image-crop.js b/web/js/components/util/image-crop.jsindex 2c43cb58a..681ffb665 100644--- a/web/js/components/util/image-crop.js+++ b/web/js/components/util/image-crop.js@@ -1,100 +1,127 @@-import React from 'react';+import React, { useState, useRef, useEffect } from 'react';import PropTypes from 'prop-types';import Cropper from 'react-image-crop';import { Portal } from 'react-portal';+import { pick, some } from 'lodash';// https://stackoverflow.com/a/13139830const TRANSPARENT_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';-/*- * A react reuseable list component- *- * @class List- * @extends React.Component- */-export default class Crop extends React.Component {- constructor(props) {- super(props);- this.state = {- crop: {- x: props.x,- y: props.y,- width: props.width,- height: props.height,- },- };+const RenderCoordinates = (props) => {+ const { coordinates, topRightStyle, bottomLeftStyle } = props;+ if (bottomLeftStyle.width < 50) {+ return '';}+ return (+ <>+ <div+ id="wv-image-top"+ className="wv-image-coords wv-image-top noselect"+ style={topRightStyle}+ >+ {coordinates.topRight}+ </div>+ <div+ id="wv-image-bottom"+ className="wv-image-coords wv-image-bottom noselect"+ style={bottomLeftStyle}+ >+ {coordinates.bottomLeft}+ </div>+ </>+ );+};++const Crop = (props) => {+ const {+ onClose,+ onChange,+ onDragStop,+ maxWidth,+ maxHeight,+ showCoordinates,+ keepSelection,+ zIndex,+ coordinates,+ topRightStyle,+ bottomLeftStyle,+ x,+ y,+ width,+ height,+ } = props;++ const [crop, setCrop] = useState({+ x,+ y,+ width,+ height,+ });+ const [loading, setLoaded] = useState(true);++ useEffect(() => {+ setCrop({+ x,+ y,+ width,+ height,+ });+ }, [x, y, width, height]);++ const onFinishDrag = (cropBoundaries) => {+ const { width: cWidth, height: cHeight } = cropBoundaries;+ if (loading) return setLoaded(false); // Hack -- prevent event from triggering onload- renderCoords() {- const { coordinates, topRightStyle, bottomLeftStyle } = this.props;- if (bottomLeftStyle.width < 50) {- return '';+ // https://github.com/DominicTobias/react-image-crop/issues/397+ const changed = cWidth && cWidth > 0 && cHeight && cHeight > 0+ && some(pick(cropBoundaries, 'x', 'y', 'width', 'height'),+ (value, key) => value !== prevCrop.current[key]);+ if (changed) {+ onDragStop(cropBoundaries);+ } else {+ onClose();}- return (- <>- <div- id="wv-image-top"- className="wv-image-coords wv-image-top noselect"- style={topRightStyle}- >- {coordinates.topRight}- </div>- <div- id="wv-image-bottom"- className="wv-image-coords wv-image-bottom noselect"- style={bottomLeftStyle}- >- {coordinates.bottomLeft}- </div>- </>- );- }+ };++ const onDrag = (cropBoundaries) => {+ if (loading) return;+ setCrop(cropBoundaries);+ if (cropBoundaries.width && cropBoundaries.height) {+ onChange(cropBoundaries);+ }+ };+ const prevCrop = useRef(crop);- render() {- const {- onClose,- onChange,- onDragStop,- maxWidth,- maxHeight,- showCoordinates,- keepSelection,- zIndex,- } = this.props;- const { crop } = this.state;- return (- <Portal node={document && document.getElementById('wv-content')}>- {showCoordinates ? this.renderCoords() : ''}- <Cropper- crop={crop}- src={TRANSPARENT_GIF}- style={{- background:- crop.width && crop.height ? 'none' : 'rgba(0, 0, 0, 0.5)',- zIndex,- }}- imageStyle={{- width: maxWidth,- height: maxHeight,- }}- keepSelection={keepSelection}- onComplete={(crop) => {- onDragStop(crop);- if (!crop.width || !crop.height) {- onClose();- }- }}- onChange={(crop) => {- this.setState({ crop });- if (crop.width && crop.height) {- onChange(crop);- }- }}+ return (+ <Portal node={document && document.getElementById('wv-content')}>+ {showCoordinates && (+ <RenderCoordinates+ coordinates={coordinates}+ topRightStyle={topRightStyle}+ bottomLeftStyle={bottomLeftStyle}/>- </Portal>- );- }-}+ )}++ <Cropper+ crop={crop}+ src={TRANSPARENT_GIF}+ style={{+ background: crop.width && crop.height ? 'none' : 'rgba(0, 0, 0, 0.5)',+ zIndex,+ }}+ imageStyle={{+ width: maxWidth,+ height: maxHeight,+ }}+ keepSelection={keepSelection}+ onComplete={onFinishDrag}+ onChange={onDrag}+ />+ </Portal>+ );+};+export default Crop;+Crop.defaultProps = {height: 10,maxHeight: window.innerWidth,@@ -106,6 +133,13 @@ Crop.defaultProps = {y: 10,zIndex: 3,};++RenderCoordinates.propTypes = {+ coordinates: PropTypes.object,+ topRightStyle: PropTypes.object,+ bottomLeftStyle: PropTypes.object,+};+Crop.propTypes = {onChange: PropTypes.func.isRequired,onClose: PropTypes.func.isRequired,diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.jsindex e81d247c6..ce3dcd738 100644--- a/web/js/containers/image-download.js+++ b/web/js/containers/image-download.js@@ -3,14 +3,14 @@ import PropTypes from 'prop-types';import { connect } from 'react-redux';import * as olProj from 'ol/proj';import { debounce as lodashDebounce } from 'lodash';-import Panel from '../components/image-download/panel';+import ImageDownloadPanel from '../components/image-download/image-download-panel';import Crop from '../components/util/image-crop';import { onToggle } from '../modules/modal/actions';import ErrorBoundary from './error-boundary';import {getAlertMessageIfCrossesDateline,imageUtilCalculateResolution,- imageUtilGetCoordsFromPixelValues,+ imageUtilGetPixelValuesFromCoords,} from '../modules/image-download/util';import util from '../util/util';import {@@ -35,21 +35,91 @@ class ImageDownloadContainer extends Component {constructor(props) {super(props);const { onBoundaryChange, screenHeight, screenWidth } = props;++ const boundaries = props.boundaries || {+ x: screenWidth / 2 - 100,+ y: screenHeight / 2 - 100,+ x2: screenWidth / 2 + 100,+ y2: screenHeight / 2 + 100,+ };+ const {+ x, y, y2, x2,+ } = boundaries;+ const bottomLeftLatLong = this.getLatLongFromPixelValue(x, y2);+ const topRightLatLong = this.getLatLongFromPixelValue(x2, y);+this.state = {fileType: props.fileType,resolution: props.resolution,isWorldfile: props.isWorldfile,- boundaries: props.boundaries || {- x: screenWidth / 2 - 100,- y: screenHeight / 2 - 100,- x2: screenWidth / 2 + 100,- y2: screenHeight / 2 + 100,- },+ bottomLeftLatLong,+ topRightLatLong,+ boundaries,};- this.debounceBoundaryUpdate = lodashDebounce(onBoundaryChange, 200);+ this.debounceBoundaryStateUpdate = lodashDebounce(onBoundaryChange, 200);this.onBoundaryChange = this.onBoundaryChange.bind(this);+ this.onLatLongChange = this.onLatLongChange.bind(this);+ }++ /**+ * Convert pixel value to latitude longitude value+ * @param {Array} pixelX+ * @param {Array} pixelY+ *+ * @returns {Array}+ */+ getLatLongFromPixelValue(pixelX, pixelY) {+ const { proj, map } = this.props;+ const coordinate = map.ui.selected.getCoordinateFromPixel([Math.floor(pixelX), Math.floor(pixelY)]);+ const { crs } = proj.selected;+ const [x, y] = olProj.transform(coordinate, crs, 'EPSG:4326');++ return [Number(x.toFixed(4)), Number(y.toFixed(4))];+ }++ /**+ * Get the crop boundaries from coordinate values+ * @param {Array} lonLat1 bottom left value+ * @param {Array} lonLat2 top right values+ *+ * @returns {Object}+ */+ getBoundaries(lonLat1, lonLat2) {+ const { map, proj } = this.props;+ const { crs } = proj.selected;+ const lonLatBottomLeft = olProj.transform(lonLat1, 'EPSG:4326', crs);+ const lonLatTopRight = olProj.transform(lonLat2, 'EPSG:4326', crs);+ const {+ x, y, x2, y2,+ } = imageUtilGetPixelValuesFromCoords(lonLatBottomLeft, lonLatTopRight, map.ui.selected);++ return {+ x, y, x2, y2,+ };}+ /**+ * Update latitude longitude state+ * with change from input+ * @param {Array} coordsArray extent array+ *+ * @returns {null}+ */+ onLatLongChange(coordsArray) {+ const bottomLeftLatLong = [coordsArray[0], coordsArray[1]];+ const topRightLatLong = [coordsArray[2], coordsArray[3]];+ const boundaries = this.getBoundaries(bottomLeftLatLong, topRightLatLong);+ this.setState({ bottomLeftLatLong, topRightLatLong, boundaries });+ this.debounceBoundaryStateUpdate(boundaries);+ }++ /**+ * Update latitude longitude values on+ * crop change+ * @param {Object} boundaries+ *+ * @returns {null}+ */onBoundaryChange(boundaries) {const {x, y, width, height,@@ -60,9 +130,10 @@ class ImageDownloadContainer extends Component {x2: x + width,y2: y + height,};-- this.setState({ boundaries: newBoundaries });- this.debounceBoundaryUpdate(newBoundaries);+ const bottomLeftLatLong = this.getLatLongFromPixelValue(newBoundaries.x, newBoundaries.y2);+ const topRightLatLong = this.getLatLongFromPixelValue(newBoundaries.x2, newBoundaries.y);+ this.setState({ bottomLeftLatLong, topRightLatLong, boundaries: newBoundaries });+ this.debounceBoundaryStateUpdate(newBoundaries);}render() {@@ -80,48 +151,49 @@ class ImageDownloadContainer extends Component {onPanelChange,} = this.props;const {- boundaries, resolution, isWorldfile, fileType,+ resolution, isWorldfile, fileType, bottomLeftLatLong, topRightLatLong, boundaries,} = this.state;+ const { crs } = proj.selected;const {x, y, x2, y2,} = boundaries;+ const lonLat1 = olProj.transform(bottomLeftLatLong, 'EPSG:4326', crs);+ const lonLat2 = olProj.transform(topRightLatLong, 'EPSG:4326', crs);const isGeoProjection = proj.id === 'geographic';const fileTypes = isGeoProjection ? fileTypesGeo : fileTypesPolar;const resolutions = isGeoProjection ? resolutionsGeo : resolutionsPolar;- const lonlats = imageUtilGetCoordsFromPixelValues(- boundaries,- map.ui.selected,- );- const { crs } = proj.selected;- const geolonlat1 = olProj.transform(lonlats[0], crs, 'EPSG:4326');- const geolonlat2 = olProj.transform(lonlats[1], crs, 'EPSG:4326');-+ const mapView = map.ui.selected.getView();const newResolution = resolution|| imageUtilCalculateResolution(- Math.round(map.ui.selected.getView().getZoom()),+ Math.round(mapView.getZoom()),isGeoProjection,proj.selected.resolutions,);- const boxTopLongitude = Math.abs(geolonlat1[0]) > 180 ? util.normalizeWrappedLongitude(geolonlat1[0]) : geolonlat1[0];- const boxBottomLongitude = Math.abs(geolonlat2[0]) > 180 ? util.normalizeWrappedLongitude(geolonlat2[0]) : geolonlat2[0];+ const viewExtent = mapView.calculateExtent(map.ui.selected.getSize());+ const normalizedBottomLeftLatLong = [util.normalizeWrappedLongitude(bottomLeftLatLong[0]), bottomLeftLatLong[1]];+ const normalizedTopRightLatLong = [util.normalizeWrappedLongitude(topRightLatLong[0]), topRightLatLong[1]];+return (<ErrorBoundary>- <Panel+ <ImageDownloadPanelprojection={proj}fileTypes={fileTypes}fileType={fileType}resolutions={resolutions}- lonlats={lonlats}+ lonlats={[lonLat1, lonLat2]}resolution={newResolution}isWorldfile={isWorldfile}hasSubdailyLayers={hasSubdailyLayers}markerCoordinates={markerCoordinates}date={date}- datelineMessage={getAlertMessageIfCrossesDateline(date, geolonlat1, geolonlat2, proj)}+ datelineMessage={getAlertMessageIfCrossesDateline(date, bottomLeftLatLong, topRightLatLong, proj)}url={url}- crs={crs}+ viewExtent={viewExtent}getLayers={getLayers}onPanelChange={onPanelChange}+ onLatLongChange={this.onLatLongChange}+ geoLatLong={[normalizedBottomLeftLatLong, normalizedTopRightLatLong]}+ map={map.ui.selected}/><Cropx={x}@@ -143,8 +215,8 @@ class ImageDownloadContainer extends Component {width: x2 - x,}}coordinates={{- bottomLeft: util.formatCoordinate([boxTopLongitude, geolonlat1[1]]),- topRight: util.formatCoordinate([boxBottomLongitude, geolonlat2[1]]),+ bottomLeft: util.formatCoordinate(bottomLeftLatLong),+ topRight: util.formatCoordinate(topRightLatLong),}}showCoordinates/>@@ -224,7 +296,6 @@ ImageDownloadContainer.propTypes = {onPanelChange: PropTypes.func.isRequired,proj: PropTypes.object.isRequired,url: PropTypes.string.isRequired,- boundaries: PropTypes.object,date: PropTypes.object,getLayers: PropTypes.func,hasSubdailyLayers: PropTypes.bool,@@ -233,4 +304,5 @@ ImageDownloadContainer.propTypes = {resolution: PropTypes.string,screenHeight: PropTypes.number,screenWidth: PropTypes.number,+ boundaries: PropTypes.object,};diff --git a/web/js/containers/map-interactions/ol-vector-interactions.js b/web/js/containers/map-interactions/ol-vector-interactions.jsindex cae4f54df..8d995f120 100644--- a/web/js/containers/map-interactions/ol-vector-interactions.js+++ b/web/js/containers/map-interactions/ol-vector-interactions.js@@ -112,6 +112,7 @@ export class VectorInteractions extends React.Component {if (hasFeatures && !isShowingClick && !measureIsActive) {let isActiveLayer = false;map.forEachFeatureAtPixel(pixel, (feature, layer) => {+ if (!layer) return;const def = lodashGet(layer, 'wv.def');const layerExtent = layer.get('extent');const pixelCoords = map.getCoordinateFromPixel(pixel);diff --git a/web/js/modules/image-download/util.js b/web/js/modules/image-download/util.jsindex 227a4800d..6bdf1f6c9 100644--- a/web/js/modules/image-download/util.js+++ b/web/js/modules/image-download/util.js@@ -292,6 +292,7 @@ export function imageUtilEstimateResolution(resolution, isGeoProjection) {? resolution / POLAR_ESTIMATION_CONSTANT: resolution / GEO_ESTIMATION_CONSTANT;}+export function imageUtilGetConversionFactor(proj) {if (proj === 'geographic') return POLAR_ESTIMATION_CONSTANT;return GEO_ESTIMATION_CONSTANT;@@ -299,20 +300,29 @@ export function imageUtilGetConversionFactor(proj) {/** Retrieves coordinates from pixel- *- * @method getCoords- * @private- ** @returns {array} array of coords- **/export function imageUtilGetCoordsFromPixelValues(pixels, map) {+ const {+ x, y, x2, y2,+ } = pixels;return [- map.getCoordinateFromPixel([Math.floor(pixels.x), Math.floor(pixels.y2)]),- map.getCoordinateFromPixel([Math.floor(pixels.x2), Math.floor(pixels.y)]),+ map.getCoordinateFromPixel([Math.floor(x), Math.floor(y2)]),+ map.getCoordinateFromPixel([Math.floor(x2), Math.floor(y)]),];}+export function imageUtilGetPixelValuesFromCoords(bottomLeft, topRight, map) {+ const [x, y2] = map.getPixelFromCoordinate([bottomLeft[0], bottomLeft[1]]);+ const [x2, y] = map.getPixelFromCoordinate([topRight[0], topRight[1]]);+ return {+ x: Math.round(x),+ y: Math.round(y),+ x2: Math.round(x2),+ y2: Math.round(y2),+ };+}+/*** Given a bounding box as an array of a lower left coordinate pair* and an upper right coordinate pair, return the BBOX parameter valuediff --git a/web/js/util/util.js b/web/js/util/util.jsindex 8274da68e..3826b8592 100644--- a/web/js/util/util.js+++ b/web/js/util/util.js@@ -631,6 +631,7 @@ export default (function(self) {return `${coord[1].toFixed(4)}°, ${coord[0].toFixed(4)}°`;};+/*** map openlayers provided longitude value to be between -180 && 180*@@ -638,10 +639,12 @@ export default (function(self) {* @return normalized longitude value*/self.normalizeWrappedLongitude = function(longitude) {+ if (Math.abs(longitude) < 180) return longitude;const isNegative = longitude < 0;const remainder = longitude % 360;return isNegative && remainder < -180 ? remainder + 360 : !isNegative && remainder > 180 ? remainder - 360 : remainder;};+// Allows simple printf functionality with strings// arguments array contains all args passed. String must be formatted// so that first replacement starts with "{1}"diff --git a/web/scss/components/image.scss b/web/scss/components/image.scssindex e828ea55f..3d4cb3b1c 100644--- a/web/scss/components/image.scss+++ b/web/scss/components/image.scss@@ -93,3 +93,52 @@.wv-image-top {text-align: right;}++.wv-image-input-case {+ position: relative;+ border: 1px solid rgb(255 255 255 / 50%);+ margin: 5px 0;+ padding: 5px;++ & .invalid {+ font-weight: bold;+ }+}++.wv-image .wv-checkbox.disabled {+ opacity: 0.6;+}++.wv-image .wv-checkbox.disabled,+.wv-checkbox.disabled .image-gb-checkbox,+.wv-checkbox.disabled label {+ cursor: not-allowed;+}++.wv-image-input-title {+ font-size: 13px;+ padding: 5px 0;+ font-weight: 600;+ cursor: pointer;++ &:hover {+ font-weight: 900;+ }+}++.wv-image-input-subtitle {+ font-size: 12px;+ padding: 5px 0;+ font-weight: semi-bold;+}++.wv-image-label-lat-lon {+ font-size: 12px;+}++.wv-image-collapse-latlong {+ position: absolute;+ top: 10px;+ right: 20px;+ width: 5px;+}diff --git a/web/scss/features/toolbar.scss b/web/scss/features/toolbar.scssindex 15b3b1af8..a1ce48a06 100644--- a/web/scss/features/toolbar.scss+++ b/web/scss/features/toolbar.scss@@ -60,7 +60,7 @@}.toolbar-medium-modal {- width: 230px;+ width: 235px;&.modal-dialog .modal-header {padding: 5px 10px 5px 6px;diff --git a/web/scss/globals.scss b/web/scss/globals.scssnew file mode 100644index 000000000..d2259d7b6--- /dev/null+++ b/web/scss/globals.scss@@ -0,0 +1,3 @@+.red-font {+ color: $wv-orange;+}diff --git a/web/scss/index.scss b/web/scss/index.scssindex 2417f6829..7e29278ff 100644--- a/web/scss/index.scss+++ b/web/scss/index.scss@@ -3,6 +3,7 @@@import "reset";@import "util";@import "mobile";+@import "globals";/* Reusable Components */@import "components/alert";diff --git a/web/scss/variables.scss b/web/scss/variables.scssindex 980aa34da..5b39301ec 100644--- a/web/scss/variables.scss+++ b/web/scss/variables.scss@@ -3,6 +3,7 @@ $wv-orange: #d54e21;$wv-transparent-black: rgb(40 40 40 / 85%);$wv-solid-black: #282828;$wv-white-font: #eee;+$wv-dark-gray: #666;/* Shadows */$wv-map-text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;