Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

a few updates

Jason Kentd6a265a64a82
diff --git a/web/css/smart-handoff.css b/web/css/smart-handoff.css
index 37dcdad5e..82f6d1c7c 100644
--- a/web/css/smart-handoff.css
+++ b/web/css/smart-handoff.css
@@ -83,7 +83,7 @@
margin-left: 52px;
}
-label[for='chk-crop-toggle'] span{
+label[for='chk-crop-toggle'] span {
color: #fff;
cursor: pointer;
}
diff --git a/web/js/containers/sidebar/smart-handoff-granule-alert.js b/web/js/components/smart-handoffs/smart-handoff-granule-alert.js
similarity index 100%
rename from web/js/containers/sidebar/smart-handoff-granule-alert.js
rename to web/js/components/smart-handoffs/smart-handoff-granule-alert.js
diff --git a/web/js/containers/sidebar/smart-handoff-modal.js b/web/js/components/smart-handoffs/smart-handoff-modal.js
similarity index 93%
rename from web/js/containers/sidebar/smart-handoff-modal.js
rename to web/js/components/smart-handoffs/smart-handoff-modal.js
index 10595050c..b6e44dd46 100644
--- a/web/js/containers/sidebar/smart-handoff-modal.js
+++ b/web/js/components/smart-handoffs/smart-handoff-modal.js
@@ -1,8 +1,9 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
-import Button from '../../components/util/button';
-import Checkbox from '../../components/util/checkbox';
+import Button from '../util/button';
+import Checkbox from '../util/checkbox';
import safeLocalStorage from '../../util/local-storage';
+import openEarthDataSearch from './util';
/**
* The Smart-Handoff components replaces the existing data download capability
@@ -11,7 +12,7 @@ import safeLocalStorage from '../../util/local-storage';
* layer data and granule files that are available for download.
*/
function SmartHandoffModal({
- dateSelection, selectedLayer, goToEarthDataSearch, showBoundingBox,
+ proj, dateSelection, selectedLayer, currentExtent, showBoundingBox,
}) {
// Hides Earthdata Search information by default
const [showMoreInfo, toggleInfo] = useState(false);
@@ -87,7 +88,7 @@ function SmartHandoffModal({
<div className="smart-handoff-button-group">
<Button
- onClick={() => goToEarthDataSearch(dateSelection, selectedLayer, showBoundingBox)} // Need to pass reference of current state of boundaries
+ onClick={() => openEarthDataSearch(proj, dateSelection, selectedLayer, currentExtent, showBoundingBox)}
id="continue-btn"
text="Continue"
className="red"
@@ -125,8 +126,9 @@ const hideModal = () => {
* Handle type-checking of defined properties
*/
SmartHandoffModal.propTypes = {
- goToEarthDataSearch: PropTypes.func,
dateSelection: PropTypes.string,
+ proj: PropTypes.string,
+ currentExtent: PropTypes.object,
selectedLayer: PropTypes.object,
showBoundingBox: PropTypes.bool,
};
diff --git a/web/js/components/smart-handoffs/util.js b/web/js/components/smart-handoffs/util.js
new file mode 100644
index 000000000..447bba4fa
--- /dev/null
+++ b/web/js/components/smart-handoffs/util.js
@@ -0,0 +1,30 @@
+import moment from 'moment';
+import util from '../../util/util';
+
+/**
+ * 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 {*} selectedLayer
+ * @param {*} extentCoords
+ * @param {*} showBoundingBox
+ */
+export default function openEarthDataSearch(proj, dateSelection, selectedLayer, extentCoords, showBoundingBox) {
+ const PROJ_CODES = {
+ arctic: '90!0!0!0!0!0',
+ geographic: '0.0!-180.0!0!1!0!0,2',
+ antarctic: '-90!180!0!2!0!0',
+ };
+ const { conceptId, daynight } = selectedLayer;
+ const { southWest, northEast } = extentCoords;
+ const startDate = `${moment.utc(dateSelection).format('YYYY-MM-DD')}T00:00:00.000Z`;
+ const endDate = `${moment.utc(dateSelection).format('YYYY-MM-DD')}T23:59:59.999Z`;
+ const params = {
+ p: conceptId,
+ '[qt]': `${startDate},${endDate}`,
+ m: PROJ_CODES[proj],
+ 'pg[0][dnf]': daynight !== undefined ? daynight : undefined,
+ 'sb[0]': showBoundingBox ? `${southWest},${northEast}` : undefined,
+ };
+ const earthDataSearchURL = `https://search.earthdata.nasa.gov/search/granules${util.toQueryString(params)}`;
+ window.open(earthDataSearchURL, '_blank');
+}
diff --git a/web/js/containers/sidebar/smart-handoff.js b/web/js/containers/sidebar/smart-handoff.js
index 4d22de526..2e60bb085 100644
--- a/web/js/containers/sidebar/smart-handoff.js
+++ b/web/js/containers/sidebar/smart-handoff.js
@@ -4,17 +4,18 @@ 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 SmartHandoffModal from '../../components/smart-handoffs/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 GranuleAlertModalBody from '../../components/smart-handoffs/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';
+import openEarthDataSearch from '../../components/smart-handoffs/util';
/**
* The Smart-Handoff components replaces the existing data download capability
@@ -67,6 +68,7 @@ class SmartHandoff extends Component {
const {
dateSelection,
activeLayers,
+ proj,
} = this.props;
const {
currentExtent,
@@ -78,19 +80,16 @@ class SmartHandoff extends Component {
const isLayerStillActive = activeLayers.find(({ conceptId }) => selectedConceptId === conceptId);
if (selectedConceptId && !isLayerStillActive) {
- this.resetState();
+ // eslint-disable-next-line react/no-did-update-set-state
+ this.setState(this.baseState);
+ }
+ if (dateSelection !== prevProps.dateSelection) {
+ this.updateGranuleCount(currentExtent);
+ }
+ if (proj.id !== prevProps.proj.id) {
+ // eslint-disable-next-line react/no-did-update-set-state
+ this.setState({ showBoundingBox: false });
}
-
- // Determine if date changed; if so, fire update on granule count
- const didDateChange = dateSelection !== prevProps.dateSelection;
- if (didDateChange) this.updateGranuleCount(currentExtent);
- }
-
- /**
- * Resets this component to it's default state
- */
- resetState() {
- this.setState(this.baseState);
}
/**
@@ -200,29 +199,30 @@ class SmartHandoff extends Component {
const startDate = `${moment.utc(dateSelection).format('YYYY-MM-DD')}T00:00:00.000Z`;
const endDate = `${moment.utc(dateSelection).format('YYYY-MM-DD')}T23:59:59.999Z`;
const dateRange = `${startDate},${endDate}`;
+ const { daynight } = selectedLayer;
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}`;
+ const params = {
+ temporal: dateRange,
+ collection_concept_id: selectedLayer.conceptId,
+ include_facets: 'v2',
+ page_size: 0,
+ day_night_flag: daynight || undefined,
+ };
- let urlSelectedGranules = urlTotalGranules;
+ let granuleRequestUrl = `https://cmr.earthdata.nasa.gov/search/granules.json${util.toQueryString(params)}`;
// Gets the total amount of granules that the layer has
- const totalGranuleResponse = await fetch(urlTotalGranules, { timeout: 5000 });
+ const totalGranuleResponse = await fetch(granuleRequestUrl, { 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 });
+ granuleRequestUrl += `&bounding_box=${currentExtent.southWest},${currentExtent.northEast}`;
+ const selectedGranulesResponse = await fetch(granuleRequestUrl, { timeout: 5000 });
const selectedResult = await selectedGranulesResponse.json();
selectedGranules = lodashGet(selectedResult, 'feed.facets.children[0].children[0].children[0].count', 0);
}
@@ -361,11 +361,18 @@ class SmartHandoff extends Component {
{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" />)}
-
+ { !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>
@@ -403,6 +410,7 @@ class SmartHandoff extends Component {
isActive,
showWarningModal,
dateSelection,
+ proj,
} = this.props;
const {
@@ -416,7 +424,7 @@ class SmartHandoff extends Component {
// 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);
+ const hideModal = safeLocalStorage.getItem(HIDE_EDS_WARNING);
// Determine if the download button is enabled
const isValidDownload = selectedLayer && selectedLayer.id !== undefined;
@@ -441,8 +449,8 @@ class SmartHandoff extends Component {
{this.renderGranuleCount()}
<Button
onClick={() => {
- if (!showModal) showWarningModal(dateSelection, selectedLayer, currentExtent, showBoundingBox);
- else openEarthDataSearch(dateSelection, selectedLayer, currentExtent, showBoundingBox);
+ if (!hideModal) showWarningModal(proj.id, dateSelection, selectedLayer, currentExtent, showBoundingBox);
+ else openEarthDataSearch(proj.id, dateSelection, selectedLayer, currentExtent, showBoundingBox);
}}
text="DOWNLOAD VIA EARTHDATA SEARCH"
className="download-btn red"
@@ -455,37 +463,6 @@ class SmartHandoff extends Component {
}
}
-/**
- * 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 {*} selectedLayer
- * @param {*} extentCoords
- * @param {*} showBoundingBox
- */
-const openEarthDataSearch = (dateSelection, selectedLayer, extentCoords, showBoundingBox) => {
- const {
- conceptId,
- daynight,
- } = selectedLayer;
-
- const {
- southWest,
- northEast,
- } = extentCoords;
-
- const startDate = `${moment.utc(dateSelection).format('YYYY-MM-DD')}T00:00:00.000Z`;
- const endDate = `${moment.utc(dateSelection).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
*/
@@ -538,15 +515,17 @@ const mapStateToProps = (state) => {
* @param {*} dispatch | A function of the Redux store that is triggered upon a change of state.
*/
const mapDispatchToProps = (dispatch) => ({
- showWarningModal: (dateSelection, selectedLayer, showBoundingBox) => {
+ showWarningModal: (proj, dateSelection, selectedLayer, currentExtent, showBoundingBox) => {
dispatch(
openCustomContent('transferring-to-earthdata-search', {
headerText: 'Leaving Worldview',
bodyComponent: SmartHandoffModal,
desktopOnly: true,
bodyComponentProps: {
+ proj,
dateSelection,
selectedLayer,
+ currentExtent,
showBoundingBox,
goToEarthDataSearch: openEarthDataSearch,
},
diff --git a/web/js/util/util.js b/web/js/util/util.js
index 176efaa2e..a7593dfc3 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -99,8 +99,9 @@ export default (function(self) {
console.log(t, message);
return t;
};
+
/**
- * Converts an object to a query string. For exaple, the following
+ * Converts an object to a query string. For example, the following
* object:
*
* { foo: "a", format: "image/png" }
@@ -120,10 +121,10 @@ export default (function(self) {
* "format=image/png"
* @return {String} converted query string
*/
- self.toQueryString = function(kvps, exceptions) {
- exceptions = exceptions || {};
+ self.toQueryString = function(kvps, exceptions = {}) {
const parts = [];
lodashEach(kvps, (value, key) => {
+ if (!value) return;
let part = `${key}=${encodeURIComponent(value)}`;
lodashEach(exceptions, (exception) => {
const regexp = new RegExp(exception, 'ig');