Interactive interface for browsing global, full-resolution satellite imagery
WV-2094: Tracking Data Collections (#4060)
Ryan Weiler92eb09d431a6
diff --git a/web/js/containers/sidebar/layer-row.js b/web/js/containers/sidebar/layer-row.jsindex 55b627118..e57567092 100644--- a/web/js/containers/sidebar/layer-row.js+++ b/web/js/containers/sidebar/layer-row.js@@ -29,7 +29,9 @@ import OrbitTrack from './orbit-track';import Zot from './zot';import { isVectorLayerClickable } from '../../modules/layers/util';import { MODAL_PROPERTIES } from '../../modules/alerts/constants';-import { getActiveLayers, makeGetDescription } from '../../modules/layers/selectors';+import {+ getActiveLayers, makeGetDescription, getCollections,+} from '../../modules/layers/selectors';import { coverageDateFormatter } from '../../modules/date/util';import { SIDEBAR_LAYER_HOVER, MAP_RUNNING_DATA } from '../../util/constants';@@ -48,6 +50,7 @@ function LayerRow (props) {compare,layer,compareState,+ collections,paletteLegends,getPalette,palette,@@ -82,6 +85,7 @@ function LayerRow (props) {const { title } = names;const removeLayerBtnId = `close-${compareState}${encodedLayerId}`;const removeLayerBtnTitle = 'Remove Layer';+ const collectionIdentifierDescription = 'Dataset version and the source of data processing, Near Real-Time (NRT) or Standard (STD)';const layerOptionsBtnId = `layer-options-btn-${encodedLayerId}`;const layerOptionsBtnTitle = 'View Options';@@ -328,6 +332,8 @@ function LayerRow (props) {? ['far', 'eye-slash']: ['far', 'eye'];+ const collectionClass = collections?.type === 'NRT' ? 'collection-title badge badge-pill badge-secondary' : 'collection-title badge badge-pill badge-light';+const renderLayerRow = () => (<>{!isEmbedModeActive && (@@ -357,7 +363,21 @@ function LayerRow (props) {{showButtons && renderControls()}</div><h4 title={names.title}>{names.title}</h4>- <p dangerouslySetInnerHTML={{ __html: names.subtitle }} />+ <div className="instrument-collection">+ <p dangerouslySetInnerHTML={{ __html: names.subtitle }} />++ {collections && isVisible ? (+ <h6>+ <span id="collection-identifier" className={collectionClass}>+ {collections.version} {collections.type}+ <UncontrolledTooltip placement="right" target="collection-identifier" boundariesElement="wv-content" delay={{ show: 250, hide: 0 }}>+ {collectionIdentifierDescription}+ </UncontrolledTooltip>+ </span>+ </h6>+ ) : ''}+ </div>+{hasPalette ? getPaletteLegend() : ''}</div>{isVectorLayer && isVisible ? renderVectorIcon() : null}@@ -417,7 +437,7 @@ const makeMapStateToProps = () => {compareState,} = ownProps;const {- screenSize, palettes, config, embed, map, compare, proj, ui, settings, animation,+ screenSize, palettes, config, embed, map, compare, proj, ui, settings, animation, layers, date,} = state;const isMobile = screenSize.isMobileDevice;const { isDistractionFreeModeActive } = ui;@@ -436,10 +456,14 @@ const makeMapStateToProps = () => {const tracksForLayer = getActiveLayers(state).filter((activeLayer) => (layer.orbitTracks || []).some((track) => activeLayer.id === track),);+ const activeDate = compare.activeString === 'active' ? date.selected : date.selectedB;+ const convertedDate = activeDate.toISOString().split('T')[0];+ const collections = getCollections(layers, convertedDate, layer);const measurementDescriptionPath = getDescriptionPath(state, ownProps);return {compare,+ collections,tracksForLayer,measurementDescriptionPath,globalTemperatureUnit,@@ -545,6 +569,7 @@ LayerRow.propTypes = {isMobile: PropTypes.bool,isVisible: PropTypes.bool,layer: PropTypes.object,+ collections: PropTypes.object,compareState: PropTypes.string,measurementDescriptionPath: PropTypes.string,names: PropTypes.object,diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.jsindex 65dc8e0c8..d8b17703a 100644--- a/web/js/map/layerbuilder.js+++ b/web/js/map/layerbuilder.js@@ -5,8 +5,8 @@ import OlSourceWMTS from 'ol/source/WMTS';import OlSourceTileWMS from 'ol/source/TileWMS';import OlLayerGroup from 'ol/layer/Group';import OlLayerTile from 'ol/layer/Tile';+import TileState from 'ol/TileState';import OlTileGridTileGrid from 'ol/tilegrid/TileGrid';-import MVT from 'ol/format/MVT';import LayerVectorTile from 'ol/layer/VectorTile';import SourceVectorTile from 'ol/source/VectorTile';@@ -14,12 +14,15 @@ import lodashCloneDeep from 'lodash/cloneDeep';import lodashMerge from 'lodash/merge';import lodashEach from 'lodash/each';import lodashGet from 'lodash/get';+import util from '../util/util';import lookupFactory from '../ol/lookupimagetile';import granuleLayerBuilder from './granule/granule-layer-builder';import { getGranuleTileLayerExtent } from './granule/util';import { createVectorUrl, getGeographicResolutionWMS, mergeBreakpointLayerAttributes } from './util';import { datesInDateRanges, prevDateInDateRange } from '../modules/layers/util';+import { updateLayerDateCollection, updateLayerCollection } from '../modules/layers/actions';+import { getCollections } from '../modules/layers/selectors';import { getSelectedDate } from '../modules/date/selectors';import {isActive as isPaletteActive,@@ -39,11 +42,9 @@ import {LEFT_WING_EXTENT, RIGHT_WING_EXTENT, LEFT_WING_ORIGIN, RIGHT_WING_ORIGIN, CENTER_MAP_ORIGIN,} from '../modules/map/constants';-export default function mapLayerBuilder(config, cache, store) {const { getGranuleLayer } = granuleLayerBuilder(cache, store, createLayerWMTS);-/*** Return a layer, or layergroup, created with the supplied function* @param {*} createLayerFunc@@ -86,6 +87,61 @@ export default function mapLayerBuilder(config, cache, store) {};};+ const updateStoreCollectionDates = (id, version, type, date) => {+ store.dispatch(updateLayerDateCollection({+ id,+ date,+ collection: {+ version,+ type,+ },+ }));+ };++ const updateStoreCollections = (id) => {+ store.dispatch(updateLayerCollection(id));+ };++ /**+ * We define our own tile loading function in order to capture custom header values+ *+ * @param {*} tile+ * @param {*} src+ */+ const tileLoadFunction = (layer, layerDate) => async function(tile, src) {+ const date = layerDate.toISOString().split('T')[0];+ let actualId;++ const updateCollections = (headers) => {+ actualId = headers.get('layer-identifier-actual');+ if (!actualId) return;+ const state = store.getState();+ const { layers } = state;+ const collectionCheck = getCollections(layers, date, layer);+ // check if the collection & dates already exist for layer so we don't dispatch actions+ if (!collectionCheck) {+ updateStoreCollections(layer.id);+ const parts = actualId.split('_');+ const version = parts[parts.length - 2];+ const type = parts[parts.length - 1];+ updateStoreCollectionDates(layer.id, version, type, date);+ }+ };++ try {+ const response = await fetch(src);+ const data = await response.blob();+ updateCollections(response.headers);+ if (data !== undefined) {+ tile.getImage().src = URL.createObjectURL(data);+ } else {+ tile.setState(TileState.ERROR);+ }+ } catch (e) {+ tile.setState(TileState.ERROR);+ }+ };+/*** Create a new OpenLayers Layer* @param {object} def@@ -419,6 +475,7 @@ export default function mapLayerBuilder(config, cache, store) {tileGrid: new OlTileGridWMTS(tileGridOptions),wrapX: false,style: typeof style === 'undefined' ? 'default' : style,+ tileLoadFunction: tileLoadFunction(def, layerDate),};if (isPaletteActive(id, options.group, state)) {const lookup = getPaletteLookup(id, options.group, state);diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.jsindex 82743003d..5ebf628da 100644--- a/web/js/modules/layers/actions.js+++ b/web/js/modules/layers/actions.js@@ -31,6 +31,8 @@ import {UPDATE_GRANULE_LAYER_GEOMETRY,RESET_GRANULE_LAYER_OPTIONS,CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP,+ UPDATE_LAYER_COLLECTION,+ UPDATE_LAYER_DATE_COLLECTION,} from './constants';import { updateRecentLayers } from '../product-picker/util';import { getOverlayGroups, getLayersFromGroups } from './util';@@ -391,3 +393,24 @@ export function changeGranuleSatelliteInstrumentGroup(id, granulePlatform) {});};}++export function updateLayerCollection(id) {+ return (dispatch, getState) => {+ const { layers } = getState();++ const collections = layers.collections[id];+ if (!collections) {+ dispatch({+ type: UPDATE_LAYER_COLLECTION,+ id,+ });+ }+ };+}++export function updateLayerDateCollection(layerInfo) {+ return {+ type: UPDATE_LAYER_DATE_COLLECTION,+ ...layerInfo,+ };+}diff --git a/web/js/modules/layers/constants.js b/web/js/modules/layers/constants.jsindex ccd5be6c2..c8caff903 100644--- a/web/js/modules/layers/constants.js+++ b/web/js/modules/layers/constants.js@@ -16,7 +16,8 @@ export const UPDATE_GRANULE_LAYER_OPTIONS = 'LAYERS/UPDATE_GRANULE_LAYER_OPTIONSexport const UPDATE_GRANULE_LAYER_GEOMETRY = 'LAYERS/UPDATE_GRANULE_LAYER_GEOMETRY';export const RESET_GRANULE_LAYER_OPTIONS = 'LAYERS/RESET_GRANULE_LAYER_OPTIONS';export const CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP = 'LAYERS/CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP';-+export const UPDATE_LAYER_COLLECTION = 'LAYERS/UPDATE_LAYER_COLLECTION';+export const UPDATE_LAYER_DATE_COLLECTION = 'LAYERS/UPDATE_LAYER_DATE_COLLECTION';export const DEFAULT_NUM_GRANULES = 10;export const MIN_GRANULES = 1;export const MAX_GRANULES = 30;diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.jsindex 2dd03ea5a..7e0bc83ac 100644--- a/web/js/modules/layers/reducers.js+++ b/web/js/modules/layers/reducers.js@@ -20,6 +20,8 @@ import {CHANGE_GRANULE_SATELLITE_INSTRUMENT_GROUP,REORDER_OVERLAY_GROUPS,REMOVE_GROUP,+ UPDATE_LAYER_COLLECTION,+ UPDATE_LAYER_DATE_COLLECTION,} from './constants';import {SET_CUSTOM as SET_CUSTOM_PALETTE,@@ -51,6 +53,7 @@ const groupState = {export const initialState = {active: { ...groupState },activeB: { ...groupState },+ collections: {},layerConfig: {},startingLayers: [],granuleFootprints: {},@@ -339,6 +342,34 @@ export function layerReducer(state = initialState, action) {},});+ case UPDATE_LAYER_COLLECTION:+ return update(state, {+ collections: {+ $merge: {+ [action.id]: {+ dates: [],+ },+ },+ },++ });++ case UPDATE_LAYER_DATE_COLLECTION:+ return update(state, {+ collections: {+ [action.id]: {+ dates: {+ $push: [{+ version: action.collection.version,+ type: action.collection.type,+ date: action.date,+ }],+ },+ },+ },++ });+default:return state;}diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.jsindex ea526739a..d035628df 100644--- a/web/js/modules/layers/selectors.js+++ b/web/js/modules/layers/selectors.js@@ -25,6 +25,16 @@ export const getStartingLayers = createSelector([getConfig], (config) => resetLaexport const isGroupingEnabled = ({ compare, layers }) => layers[compare.activeString].groupOverlays;+export const getCollections = (layers, date, layer) => {+ if (!layers.collections[layer.id]) return;+ const dateCollection = layers.collections[layer.id].dates;+ for (let i = 0; i < dateCollection.length; i += 1) {+ if (dateCollection[i].date === date) {+ return dateCollection[i];+ }+ }+};+/*** Return a list of layers for the currently active compare state* regardless of projectiondiff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex 67df2b263..44ff6184c 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -8,7 +8,6 @@ import {isEqual as lodashIsEqual,} from 'lodash';import moment from 'moment';-import googleTagManager from 'googleTagManager';import update from 'immutability-helper';import {@@ -1276,18 +1275,10 @@ export function mapLocationToLayerState(});}- // TODO how do we properly combine initial state with location state- newStateFromLocation.layers.active = {- ...newStateFromLocation.layers.active,- granuleLayers: {},- granulePlatform: '',- };-- newStateFromLocation.layers.activeB = {- ...newStateFromLocation.layers.activeB,- granuleLayers: {},- granulePlatform: '',- };+ newStateFromLocation.layers = update(state.layers, {+ active: { $merge: newStateFromLocation.layers.active },+ activeB: { $merge: newStateFromLocation.layers.activeB },+ });return newStateFromLocation;}diff --git a/web/js/modules/layers/util.test.js b/web/js/modules/layers/util.test.jsindex 9d99fa665..ea59ff0e6 100644--- a/web/js/modules/layers/util.test.js+++ b/web/js/modules/layers/util.test.js@@ -17,6 +17,9 @@ let defaultStateFromLocation = {active: {layers: [],},+ activeB: {+ layers: [],+ },},};const globalState = fixtures.getState();@@ -107,6 +110,9 @@ describe('permalink 1.0', () => {active: {layers: [],},+ activeB: {+ layers: [],+ },},};});@@ -136,6 +142,9 @@ describe('permalink 1.1', () => {active: {layers: [],},+ activeB: {+ layers: [],+ },},};});@@ -245,6 +254,9 @@ describe('Date range building', () => {active: {layers: [],},+ activeB: {+ layers: [],+ },},};});diff --git a/web/scss/features/layers.scss b/web/scss/features/layers.scssindex 1f96c84a2..ea06aab95 100644--- a/web/scss/features/layers.scss+++ b/web/scss/features/layers.scss@@ -1002,6 +1002,16 @@}}+.collection-title {+ margin-right: 4px;+}++.instrument-collection {+ margin-top: 3px;+ display: flex;+ justify-content: space-between;+}+/** React-Swipe-To-Delete Overrides */.swipe-to-delete .js-content:first-child {position: relative !important;