Interactive interface for browsing global, full-resolution satellite imagery
Merge branch 'develop' into smart-handoffs
Jason Kent75ee82555243
diff --cc web/js/combine-ui.jsindex da41d453e,53127b5f6..5b02e542b--- a/web/js/combine-ui.js+++ b/web/js/combine-ui.js@@@ -1,8 -1,11 +1,10 @@@import util from './util/util';import mapui from './map/ui';import mapAnimate from './map/animate';-import dataUi from './map/data/ui';import naturalEventsUI from './map/natural-events/ui';+ const { events } = util;+/*** Legacy UI Rendering* @param {Object} models | Legacy Models Objectdiff --cc web/js/containers/sidebar/footer-content.jsindex 504e0480b,292221808..d2cc6efd3--- a/web/js/containers/sidebar/footer-content.js+++ b/web/js/containers/sidebar/footer-content.js@@@ -10,7 -10,13 +10,8 @@@ import { toggleCompareOnOff, changeModimport SearchUiProvider from '../../components/layer/product-picker/search-ui-provider';import { openCustomContent } from '../../modules/modal/actions';import { toggleListAll } from '../../modules/natural-events/actions';-import { DATA_GET_DATA_CLICK } from '../../modules/data/constants';import { stop as stopAnimationAction } from '../../modules/animation/actions';+ import { getActiveLayers } from '../../modules/layers/selectors';class FooterContent extends React.Component {constructor(props) {diff --cc web/js/containers/sidebar/sidebar.jsindex 47b4c0524,d0d97112c..38f66b8d9--- a/web/js/containers/sidebar/sidebar.js+++ b/web/js/containers/sidebar/sidebar.js@@@ -4,9 -4,9 +4,9 @@@ import PropTypes from 'prop-types'import { get as lodashGet } from 'lodash';import { TabContent, TabPane } from 'reactstrap';import googleTagManager from 'googleTagManager';- import Layers from './layers';+ import LayersContainer from './layers-container';import Events from './events';-import Data from './data';+import SmartHandoff from './smart-handoff';import CompareCase from './compare';import FooterContent from './footer-content';import CollapsedButton from '../../components/sidebar/collapsed-button';diff --cc web/js/containers/sidebar/smart-handoff.jsindex 6560af7e6,000000000..ad045901bmode 100644,000000..100644--- a/web/js/containers/sidebar/smart-handoff.js+++ b/web/js/containers/sidebar/smart-handoff.js@@@ -1,541 -1,0 +1,539 @@@+import React, { Component } from 'react';+import PropTypes from 'prop-types';+import { connect } from 'react-redux';+import * as olProj from 'ol/proj';+import { debounce as lodashDebounce, get as lodashGet } from 'lodash';+import moment from 'moment';+import SmartHandoffModal from './smart-handoff-modal';+import Button from '../../components/util/button';+import Checkbox from '../../components/util/checkbox';+import Crop from '../../components/util/image-crop';+import util from '../../util/util';+import GranuleAlertModalBody from './smart-handoff-granule-alert';+import { imageUtilGetCoordsFromPixelValues } from '../../modules/image-download/util';+import { onClose, openCustomContent } from '../../modules/modal/actions';++import { getActiveLayers } from '../../modules/layers/selectors';+import getSelectedDate from '../../modules/date/selectors';+import safeLocalStorage from '../../util/local-storage';++/**+ * The Smart-Handoff components replaces the existing data download capability+ * by directing users to select specific layer products within Worldview and 'hand' them 'off'+ * to NASA's Earthdata Search web tool that will proceed in fetching corresponding+ * layer data and granule files that are available for download.+ */+class SmartHandoff extends Component {+ /**+ * SmartHandoff's default constructor+ * @param {*} props | A read-only object used to transfer data from a parent component+ */+ constructor(props) {+ super(props);++ const {+ screenWidth,+ screenHeight,+ } = props;++ // Set default state+ this.state = {+ boundaries: props.boundaries || {+ x: screenWidth / 2 - 100,+ y: screenHeight / 2 - 100,+ x2: screenWidth / 2 + 100,+ y2: screenHeight / 2 + 100,+ },+ selectedLayer: undefined,+ showBoundingBox: false,+ isSearchingForGranules: false,+ selectedGranules: 0,+ totalGranules: 0,+ currentExtent: {},+ coordinates: {},+ };++ this.baseState = this.state;+ this.onBoundaryChange = this.onBoundaryChange.bind(this);+ this.updateExtent = this.updateExtent.bind(this);+ this.debouncedUpdateExtent = lodashDebounce(this.updateExtent, 250);+ }++ /**+ * When fired, compare prevProps to determine if previously selected layer is still active+ * and whether or not to update granule data base don data changes.+ * @param {*} prevProps+ */+ componentDidUpdate(prevProps) {+ const {+ selectedDate,+ activeLayers,+ } = this.props;+ const {+ currentExtent,+ selectedLayer,+ } = this.state;++ // Determine if existing selected layer is active still and visibility toggle is 'ON'+ const selectedConceptId = selectedLayer && selectedLayer.conceptId;+ const isLayerStillActive = activeLayers.find(({ conceptId }) => selectedConceptId === conceptId);++ if (selectedConceptId && !isLayerStillActive) {+ this.resetState();+ }++ // Determine if date changed; if so, fire update on granule count+ const didDateChange = selectedDate !== prevProps.selectedDate;+ if (didDateChange) this.updateGranuleCount(currentExtent);+ }++ /**+ * Resets this component to it's default state+ */+ resetState() {+ this.setState(this.baseState);+ }++ /**+ * Fires when the bounding box / crop toggle is activated and changed+ */+ updateExtent() {+ const { currentExtent, selectedLayer } = this.state;+ if (selectedLayer && currentExtent) {+ this.updateGranuleCount(currentExtent);+ }+ }++ /**+ * Fires when the image cropper is moved around on the map; updates the SW and NE lat/lon coordinates.+ * @param {*} boundaries - the focal point to which layer data should be contained within+ */+ onBoundaryChange(boundaries) {+ const { proj, map } = this.props;+ const { selectedLayer } = this.state;++ if (!selectedLayer) return;++ const {+ x,+ y,+ width,+ height,+ } = boundaries;++ const newBoundaries = {+ x,+ y,+ x2: x + width,+ y2: y + height,+ };++ const lonlats = imageUtilGetCoordsFromPixelValues(+ newBoundaries,+ map.ui.selected,+ );+ const { crs } = proj;++ // Retrieve the lat/lon coordinates based on the defining boundary and map projection+ const geolonlat1 = olProj.transform(lonlats[0], crs, 'EPSG:4326');+ const geolonlat2 = olProj.transform(lonlats[1], crs, 'EPSG:4326');++ // Determine longitude out of bounds areas and reset to limits+ if (geolonlat1[0] > 180) geolonlat1[0] = 180;+ else if (geolonlat1[0] < -180) geolonlat1[0] = -180;+ if (geolonlat2[0] > 180) geolonlat2[0] = 180;+ else if (geolonlat2[0] < -180) geolonlat2[0] = -180;++ // Determine latitude out of bounds areas and reset to limits+ if (geolonlat1[1] > 90) geolonlat1[1] = 90;+ else if (geolonlat1[1] < -90) geolonlat1[1] = -90;+ if (geolonlat2[1] > 90) geolonlat2[1] = 90;+ else if (geolonlat2[1] < -90) geolonlat2[1] = -90;++ const currentExtent = {+ southWest: `${geolonlat1[0]},${geolonlat1[1]}`,+ northEast: `${geolonlat2[0]},${geolonlat2[1]}`,+ };++ const coordinates = {+ bottomLeft: util.formatCoordinate([geolonlat1[0], geolonlat1[1]]),+ topRight: util.formatCoordinate([geolonlat2[0], geolonlat2[1]]),+ };++ this.setState({+ boundaries: newBoundaries,+ coordinates,+ currentExtent,+ }, () => {+ if (selectedLayer && currentExtent) {+ this.debouncedUpdateExtent();+ }+ });+ }++ /**+ * Fires when user selected a different layer+ * @param {*} layer - the specified layer designated by the user+ * @param {*} currentExtent - the current boundaries of the bounding box+ */+ onLayerChange(layer, currentExtent) {+ this.setState({ selectedLayer: layer }, () => this.updateGranuleCount(currentExtent));+ }++ /**+ * Asynchronous call to fetch granule data for the specified selected layer. Contains+ * conditional logic to determine which counts are provided back to the user; total+ * count vs selected count (that is if the bounding box has been enabled by the user)+ * @param {*} currentExtent+ */+ async updateGranuleCount(currentExtent) {+ const { selectedDate } = this.props;+ const {+ selectedLayer,+ showBoundingBox,+ } = this.state;++ if (!selectedLayer) return;++ // Places the compoent state in a loading state; triggers {...} animation.+ this.setState({ isSearchingForGranules: true });++ const startDate = `${moment.utc(selectedDate).format('YYYY-MM-DD')}T00:00:00.000Z`;+ const endDate = `${moment.utc(selectedDate).format('YYYY-MM-DD')}T23:59:59.999Z`;+ const dateRange = `${startDate},${endDate}`;++ let totalGranules = 0;+ let selectedGranules = 0;++ let urlTotalGranules = 'https://cmr.earthdata.nasa.gov/search/granules.json?'+ + `temporal=${dateRange}&`+ + `collection_concept_id=${selectedLayer.conceptId}&`+ + 'include_facets=v2&'+ + 'page_size=0';++ if (selectedLayer.daynight) urlTotalGranules += `&day_night_flag=${selectedLayer.daynight}`;++ let urlSelectedGranules = urlTotalGranules;++ // Gets the total amount of granules that the layer has+ const totalGranuleResponse = await fetch(urlTotalGranules, { timeout: 5000 });+ const totalResult = await totalGranuleResponse.json();+ totalGranules = lodashGet(totalResult, 'feed.facets.children[0].children[0].children[0].count', 0);++ // Gets the total subset of granules that are within the defining bounding box+ if (showBoundingBox) {+ urlSelectedGranules += `&bounding_box=${currentExtent.southWest},${currentExtent.northEast}`;+ const selectedGranulesResponse = await fetch(urlSelectedGranules, { timeout: 5000 });+ const selectedResult = await selectedGranulesResponse.json();+ selectedGranules = lodashGet(selectedResult, 'feed.facets.children[0].children[0].children[0].count', 0);+ }++ this.setState({+ selectedGranules,+ totalGranules,+ isSearchingForGranules: false,+ });+ }++ /**+ * Default render which displays the download panel+ */+ render() {+ const {+ screenWidth,+ screenHeight,+ activeLayers,+ isActive,+ showWarningModal,+ showGranuleHelpModal,+ selectedDate,+ } = this.props;++ const {+ boundaries,+ selectedLayer,+ isSearchingForGranules,+ selectedGranules,+ totalGranules,+ coordinates,+ currentExtent,+ showBoundingBox,+ } = this.state;++ // Determine if download 'smart-handoff' tab is activated by user+ if (!isActive) return null;++ const {+ x,+ y,+ x2,+ y2,+ } = boundaries;++ // Used to determine if the added smart-handoff modal should be shown+ const { HIDE_EDS_WARNING } = safeLocalStorage.keys;+ const showModal = safeLocalStorage.getItem(HIDE_EDS_WARNING);++ // Determine if the download button is enabled+ const isValidDownload = selectedLayer && selectedLayer.id !== undefined;++ const availableLayers = activeLayers.filter((layer) => layer.conceptId !== undefined).length;+ const areThereLayersToDownload = availableLayers > 0;++ const dateSelection = moment.utc(selectedDate).format('YYYY MMM DD');+++ if (areThereLayersToDownload) {+ return (+ <div className="smart-handoff-side-panel">++ <h1>Select an available layer to download:</h1>++ <div className="esd-notification">+ Downloading data will be performed using+ {' '}+ <a href="https://search.earthdata.nasa.gov" target="_blank" rel="noopener noreferrer">NASA's Earthdata Search</a>+ {' '}+ application.+ </div>++ <hr />++ <div className="smart-handoff-layer-list">+ {activeLayers.map((layer) => {+ if (layer.conceptId) {+ const inputId = `${util.encodeId(layer.id)}-smart-handoff-choice`;+ return (+ <div className="layer-item" key={inputId}>+ <input+ id={inputId}+ type="radio"+ value={layer.conceptId}+ name="smart-handoff-layer-radio"+ checked={selectedLayer && selectedLayer.id === layer.id}+ onChange={() => this.onLayerChange(layer, currentExtent)}+ />+ <label htmlFor={inputId}>{layer.title}</label>+ <span>{layer.subtitle}</span>+ </div>+ );+ }+ return null;+ })}+ </div>++ <hr />++ <div className="smart-handoff-crop-toggle">+ <Checkbox+ id="chk-crop-toggle"+ label="Target Area Selection"+ text="Toggle boundary selection."+ color="gray"+ checked={showBoundingBox}+ onCheck={() => {+ this.setState({ showBoundingBox: !showBoundingBox }, () => {+ if (selectedLayer && selectedLayer.id) this.updateGranuleCount(currentExtent);+ });+ }}+ />+ </div>++ <hr />++ {selectedLayer && selectedLayer.conceptId && (+ <div className="granule-count">+ <h1>+ Available granules for+ {' '}+ {dateSelection}+ :+ {' '}+ { !isSearchingForGranules && totalGranules === 0 && (<span className="fade-in constant-width">NONE</span>)}+ { !showBoundingBox && !isSearchingForGranules && totalGranules !== 0 && (<span className="fade-in constant-width">{totalGranules}</span>)}+ { showBoundingBox && !isSearchingForGranules && totalGranules !== 0 && (<span className="fade-in constant-width">{`${selectedGranules} of ${totalGranules}`}</span>)}+ { isSearchingForGranules && (<span className="loading-granule-count fade-in constant-width" />)}++ <span className="granule-help-link" onClick={() => showGranuleHelpModal()}>(?)</span>++ </h1>+ </div>+ )}++ <Button+ onClick={() => {+ if (!showModal) showWarningModal(selectedDate, selectedLayer, currentExtent, showBoundingBox);+ else openEarthDataSearch(selectedDate, selectedLayer, currentExtent, showBoundingBox)();+ }}+ text="DOWNLOAD VIA EARTHDATA SEARCH"+ className="download-btn red"+ valid={!!isValidDownload}+ />++ { showBoundingBox && (+ <Crop+ className="download-extent"+ x={x}+ y={y}+ width={x2 - x}+ height={y2 - y}+ maxHeight={screenHeight}+ maxWidth={screenWidth}+ onChange={this.onBoundaryChange}+ onClose={onClose}+ keepSelection+ bottomLeftStyle={{+ left: x,+ top: y2 + 5,+ width: x2 - x,+ }}+ topRightStyle={{+ left: x,+ top: y - 20,+ width: x2 - x,+ }}+ coordinates={coordinates}+ showCoordinates+ />+ )}+ </div>+ );+ }+ return (+ <div className="smart-handoff-side-panel">+ <h1>+ None of your currently listed layers are available for downloading.+ </h1>+ <hr />+ <h2>Why are my current layers not available?</h2>+ <p>+ Some layers in Worldview do not have corresponding source data products available for download.+ </p>+ <p>+ These include National Boundaries, Orbit Tracks, Earth at Night, and MODIS Corrected Reflectance products.+ </p>+ <p>+ If you would like to download only an image, please use the “camera” icon in the upper right.+ </p>+ </div>+ );+ }+}++/**+ * Method call to direct the user to Earthdata Search with the necessary URL parameters that+ * encapsulate what the user is intending to try and download data / granules from+ * @param {*} selectedDate+ * @param {*} selectedLayer+ * @param {*} extentCoords+ * @param {*} showBoundingBox+ */+const openEarthDataSearch = (selectedDate, selectedLayer, extentCoords, showBoundingBox) => () => {+ const {+ conceptId,+ daynight,+ } = selectedLayer;++ const {+ southWest,+ northEast,+ } = extentCoords;++ const startDate = `${moment.utc(selectedDate).format('YYYY-MM-DD')}T00:00:00.000Z`;+ const endDate = `${moment.utc(selectedDate).format('YYYY-MM-DD')}T23:59:59.999Z`;++ const dateRange = `${startDate},${endDate}`;++ let earthDataSearchURL = `https://search.earthdata.nasa.gov/search/granules?p=${conceptId}&[qt]=${dateRange}&m=0.0!-180.0!0!1!0!0,2`;++ if (daynight) earthDataSearchURL += `&pg[0][dnf]=${daynight}`;+ if (showBoundingBox) earthDataSearchURL += `&sb=${southWest},${northEast}`;++ window.open(earthDataSearchURL, '_blank');+};++/**+ * Handle type-checking of defined properties+ */+SmartHandoff.propTypes = {+ isActive: PropTypes.bool,+ activeLayers: PropTypes.array,+ map: PropTypes.object.isRequired,+ boundaries: PropTypes.object,+ proj: PropTypes.object,+ screenHeight: PropTypes.number,+ screenWidth: PropTypes.number,+ selectedDate: PropTypes.instanceOf(Date),+ showWarningModal: PropTypes.func,+ showGranuleHelpModal: PropTypes.func,+};++/**+ * ReactRedux; used for selecting the part of the data from the store+ * that the Smarthandoff component needs. This is called every time the+ * store state changes.+ * @param {*} state | Encapsulates the entire Redux store state.+ */+const mapStateToProps = (state) => {+ const {+ browser,- layers,+ map,+ proj,- compare,+ sidebar,+ boundaries,+ } = state;++ const {+ screenWidth,+ screenHeight,+ } = browser;+- const { activeString } = compare;- const activeLayers = layers[activeString].filter((layer) => layer.projections[proj.id]);++ const activeLayers = getActiveLayers(state).filter((layer) => layer.projections[proj.id]);++ return {+ activeLayers,+ boundaries,+ isActive: sidebar.activeTab === 'download',+ map,+ proj: proj.selected,+ screenWidth,+ screenHeight,+ selectedDate: getSelectedDate(state),+ };+};++/**+ * React-Redux; used for SmartHandoff component to fire specific actions events+ * @param {*} dispatch | A function of the Redux store that is triggered upon a change of state.+ */+const mapDispatchToProps = (dispatch) => ({+ showWarningModal: (selectedDate, selectedLayer, extentCoords, showBoundingBox) => {+ dispatch(+ openCustomContent('transferring-to-earthdata-search', {+ headerText: 'Leaving Worldview',+ bodyComponent: SmartHandoffModal,+ bodyComponentProps: {+ selectedDate,+ selectedLayer,+ extentCoords,+ showBoundingBox,+ goToEarthDataSearch: openEarthDataSearch(selectedDate, selectedLayer, extentCoords, showBoundingBox),+ },+ size: 'lg',+ }),+ );+ },+ showGranuleHelpModal: () => {+ dispatch(+ openCustomContent('granule-help', {+ headerText: 'Granule Availablilty',+ bodyComponent: GranuleAlertModalBody,+ size: 'lg',+ }),+ );+ },+});++export default connect(+ mapStateToProps,+ mapDispatchToProps,+)(SmartHandoff);diff --cc web/js/containers/toolbar.jsindex 106d06bb9,e30560c6a..aaee0f1dc--- a/web/js/containers/toolbar.js+++ b/web/js/containers/toolbar.js@@@ -339,7 -339,7 +339,7 @@@ class toolbarContainer extends Componenconst mapStateToProps = (state) => {const {- animation, browser, notifications, palettes, compare, map, measure, modal, layers, proj, ui, geosearch,- animation, browser, notifications, palettes, compare, map, measure, modal, data, ui, geosearch,++ animation, browser, notifications, palettes, compare, map, measure, modal, ui, geosearch,} = state;const { isDistractionFreeModeActive } = ui;const { number, type } = notifications;diff --cc web/js/location.jsindex 1f909d250,21e35658e..6c76587e6--- a/web/js/location.js+++ b/web/js/location.js@@@ -1,5 -1,6 +1,5 @@@- import { assign as lodashAssign, get } from 'lodash';+ import { get } from 'lodash';import update from 'immutability-helper';-import { encode } from './modules/link/util';// legacy crutchesimport {serializeDate, tryCatchDate, parsePermalinkDate, mapLocationToDateState,diff --cc web/js/map/ui.jsindex a37551bb6,cc99746ff..fe41aa451--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@@ -1219,26 -1181,21 +1180,20 @@@ export default function mapui(models, cif (self.mapIsbeingDragged) {return;}-- // Don't add data runners if we're on the events or data tabs, or if map is animating+ // Don't add data runners if we're on the events or smart handoffs tabs, or if map is animatingconst isEventsTabActive = typeof state.events !== 'undefined' && state.events.active;- const isDataTabActive = typeof state.data !== 'undefined' && state.data.active;const isMapAnimating = state.animation.isPlaying;- if (isEventsTabActive || isDataTabActive || isMapAnimating) return;+ // TODO handle smart handoffs+ if (isEventsTabActive || isMapAnimating) return;dataRunner.newPoint(pixels, map);- }- $(map.getViewport())- .mouseout((e) => {- if (- $(e.relatedTarget).hasClass('map-coord')- || $(e.relatedTarget).hasClass('coord-btn')- ) {- return;- }- hoverThrottle.cancel();- dataRunner.clearAll();- })- .mousemove(hoverThrottle = lodashThrottle(onMouseMove, 300));+ }, 300);++ events.on('map:mousemove', throttledOnMouseMove);+ events.on('map:mouseout', (e) => {+ throttledOnMouseMove.cancel();+ dataRunner.clearAll();+ });}init();diff --cc web/js/modules/layers/actions.jsindex e72025dcd,04c2c0a62..a0c251783--- a/web/js/modules/layers/actions.js+++ b/web/js/modules/layers/actions.js@@@ -18,7 -23,10 +23,9 @@@ importUPDATE_OPACITY,ADD_LAYERS_FOR_EVENT,} from './constants';-import { selectProduct } from '../data/actions';import { updateRecentLayers } from '../product-picker/util';+ import { getOverlayGroups, getLayersFromGroups } from './util';+ import safeLocalStorage from '../../util/local-storage';export function resetLayers(activeString) {return (dispatch, getState) => {