Interactive interface for browsing global, full-resolution satellite imagery
hide layers without snapshot #3343
Ben Kingc06e49c0aa79
diff --git a/config/default/common/config/wv.json/layers/multi-mission/hls/HLS_MGRS_Granule_Grid.json b/config/default/common/config/wv.json/layers/multi-mission/hls/HLS_MGRS_Granule_Grid.jsonindex d69a833b3..18cb254ab 100644--- a/config/default/common/config/wv.json/layers/multi-mission/hls/HLS_MGRS_Granule_Grid.json+++ b/config/default/common/config/wv.json/layers/multi-mission/hls/HLS_MGRS_Granule_Grid.json@@ -10,7 +10,8 @@"layergroup": "Reference","product": "","type": "vector",- "wrapX": true+ "wrapX": true,+ "snapshot": false}}}\ No newline at end of filediff --git a/doc/config/layers.md b/doc/config/layers.mdindex 06d212596..61ec8250b 100644--- a/doc/config/layers.md+++ b/doc/config/layers.md@@ -105,6 +105,7 @@ Example:* **track**: Classify a layer's track direction. This will usually be either ascending or descending and will be displayed within the title of the layer in the Measurement / Sources add modal view if provided.* **description**: Point to a markdown file within the metadata folder to provide a layer description.* **wrapX**: Wrap the layer across the anti-meridian.+* **snapshot**: Ability to be downloaded via worldview snapshots (WVS). Default is `true`.* **wrapadjacentdays**: Wrap the layer across the anti-meridian but select the previous day when greater than 180 and the next day when less than -180.* **palette**: To display a color palette legend, a `palette` object should exist with the following properties:* **id**: Identifier of the palette. This should match the name of the colormap file without the extension.diff --git a/schemas/layer-config.json b/schemas/layer-config.jsonindex 1aa45eb7a..e620e56c0 100644--- a/schemas/layer-config.json+++ b/schemas/layer-config.json@@ -5,12 +5,14 @@"description": "Layer Configuration Schema","type": "object","properties": {- "layers": {- "type": "object",- "patternProperties": {- "^.": { "$ref": "#/definitions/layer" }- }- }+ "layers": {+ "type": "object",+ "patternProperties": {+ "^.": {+ "$ref": "#/definitions/layer"+ }+ }+ }},"definitions": {"layer": {@@ -36,17 +38,27 @@"tags": {"type": "string"},+ "snapshot": {+ "type": "boolean"+ },"group": {"type": "string",- "enum": ["overlays", "baselayers"]+ "enum": [+ "overlays",+ "baselayers"+ ]},"layergroup": {"type": "string"},"product": {"anyOf": [- { "type": "string" },- { "type": "array" }+ {+ "type": "string"+ },+ {+ "type": "array"+ }]},"palette": {@@ -71,7 +83,10 @@"type": "array","items": {"type": "string",- "enum": ["day", "night"]+ "enum": [+ "day",+ "night"+ ]}},"period": {@@ -178,14 +193,18 @@"if": {"properties": {"id": {- "not": { "const": "World_Database_on_Protected_Areas" }+ "not": {+ "const": "World_Database_on_Protected_Areas"+ }}}},"then": {"properties": {"layer": {- "not": { "type": "string" }+ "not": {+ "type": "string"+ }}}}@@ -194,12 +213,18 @@"description": "","if": {"properties": {- "type": { "const": "wms" }+ "type": {+ "const": "wms"+ }},- "required": [ "type" ]+ "required": [+ "type"+ ]},"then": {- "required": [ "format" ]+ "required": [+ "format"+ ]}}]@@ -246,7 +271,9 @@"type": "string"}},- "required": [ "id" ]+ "required": [+ "id"+ ]},"palette": {"type": "object",@@ -300,7 +327,9 @@}},"additionalProperties": true,- "required": [ "source" ]+ "required": [+ "source"+ ]}}}\ No newline at end of filediff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.jsindex 288295319..276803af3 100644--- a/web/js/containers/animation-widget.js+++ b/web/js/containers/animation-widget.js@@ -2,6 +2,7 @@ import React from 'react';import { connect } from 'react-redux';import {find as lodashFind,+ filter as lodashFilter,get as lodashGet,cloneDeep as lodashCloneDeep,} from 'lodash';@@ -60,8 +61,11 @@ import { notificationWarnings } from '../modules/image-download/constants';import { onToggle, openCustomContent } from '../modules/modal/actions';import { clearCustoms, refreshPalettes } from '../modules/palettes/actions';import { clearRotate, refreshRotation } from '../modules/map/actions';-import { clearGraticule, refreshGraticule } from '../modules/layers/actions';+import {+ clearGraticule, refreshGraticule, hideLayers, showLayers,+} from '../modules/layers/actions';import { hasCustomPaletteInActiveProjection } from '../modules/palettes/util';+import { getNonDownloadableLayers, getNonDownloadableLayerWarning, hasNonDownloadableVisibleLayer } from '../modules/image-download/util';const RangeHandle = (props) => {@@ -189,10 +193,11 @@ class AnimationWidget extends React.Component {});}- getPromise(bool, type, action, title) {+ getPromise(bool, type, action) {+ const { visibleLayersForProj } = this.props;const { notify } = this.props;if (bool) {- return notify(type, action);+ return notify(type, action, visibleLayersForProj);}return Promise.resolve(type);}@@ -382,6 +387,8 @@ class AnimationWidget extends React.Component {activePalettes,numberOfFrames,refreshStateAfterGif,+ hasNonDownloadableLayer,+ visibleLayersForProj,} = this.props;const gifDisabled = numberOfFrames >= maxFrames;const elemExists = document.querySelector('#create-gif-button');@@ -400,16 +407,19 @@ class AnimationWidget extends React.Component {if (numberOfFrames >= maxFrames) {return;}+ const nonDownloadableLayers = hasNonDownloadableLayer ? getNonDownloadableLayers(visibleLayersForProj) : null;const paletteStore = lodashCloneDeep(activePalettes);+await this.getPromise(hasCustomPalettes, 'palette', clearCustoms, 'Notice');await this.getPromise(isRotated, 'rotate', clearRotate, 'Reset rotation');await this.getPromise(hasGraticule, 'graticule', clearGraticule, 'Remove Graticule?');+ await this.getPromise(hasNonDownloadableLayer, 'layers', hideLayers, 'Remove Layers?');await onUpdateStartAndEndDate(startDate, endDate);googleTagManager.pushEvent({event: 'GIF_create_animated_button',});this.onCloseGif = () => {- refreshStateAfterGif(hasCustomPalettes ? paletteStore : undefined, rotation, hasGraticule);+ refreshStateAfterGif(hasCustomPalettes ? paletteStore : undefined, rotation, hasGraticule, nonDownloadableLayers);toggleGif();};toggleGif();@@ -690,6 +700,7 @@ function mapStateToProps(state) {maxFrames,);const { rotation } = map;+ const visibleLayersForProj = lodashFilter(activeLayersForProj, 'visible');return {appNow,screenWidth: browser.screenWidth,@@ -717,6 +728,8 @@ function mapStateToProps(state) {looping: loop,hasCustomPalettes,map,+ hasNonDownloadableLayer: hasNonDownloadableVisibleLayer(visibleLayersForProj),+ visibleLayersForProj,promiseImageryForTime: (date, layers) => promiseImageryForTime(date, layers, state),isGifActive: gifActive,isCompareActive: compare.active,@@ -734,14 +747,15 @@ const mapDispatchToProps = (dispatch) => ({selectDate: (val) => {dispatch(selectDate(val));},- notify: (type, action, title) => new Promise((resolve, reject, cancel) => {+ notify: (type, action, visibleLayersForProj) => new Promise((resolve, reject, cancel) => {+ const nonDownloadableLayers = type !== 'layers' ? null : getNonDownloadableLayers(visibleLayersForProj);const bodyComponentProps = {- bodyText: notificationWarnings[type],+ bodyText: type !== 'layers' ? notificationWarnings[type] : getNonDownloadableLayerWarning(nonDownloadableLayers),cancel: () => {dispatch(onToggle());},accept: () => {- dispatch(action());+ dispatch(action(nonDownloadableLayers));dispatch(onToggle());resolve();},@@ -771,7 +785,7 @@ const mapDispatchToProps = (dispatch) => ({toggleGif: () => {dispatch(toggleComponentGifActive());},- refreshStateAfterGif: (activePalettes, rotation, isGraticule) => {+ refreshStateAfterGif: (activePalettes, rotation, isGraticule, nonDownloadableLayers) => {if (activePalettes) {dispatch(refreshPalettes(activePalettes));}@@ -781,6 +795,9 @@ const mapDispatchToProps = (dispatch) => ({if (isGraticule) {dispatch(refreshGraticule(isGraticule));}+ if (nonDownloadableLayers) {+ dispatch(showLayers(nonDownloadableLayers));+ }},toggleCustomModal: (open, toggleBy) => {dispatch(toggleCustomModal(open, toggleBy));@@ -819,6 +836,7 @@ AnimationWidget.propTypes = {appNow: PropTypes.object,activePalettes: PropTypes.object,animationCustomModalOpen: PropTypes.bool,+ visibleLayersForProj: PropTypes.array,changeCustomInterval: PropTypes.func,currentDate: PropTypes.object,customDelta: PropTypes.number,@@ -829,6 +847,7 @@ AnimationWidget.propTypes = {hasCustomPalettes: PropTypes.bool,hasFutureLayers: PropTypes.bool,hasGraticule: PropTypes.bool,+ hasNonDownloadableLayer: PropTypes.bool,hasSubdailyLayers: PropTypes.bool,interval: PropTypes.string,isActive: PropTypes.bool,diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.jsindex 34309b1b2..a50260b8a 100644--- a/web/js/containers/toolbar.js+++ b/web/js/containers/toolbar.js@@ -6,6 +6,7 @@ import {get as lodashGet,find as lodashFind,cloneDeep as lodashCloneDeep,+ filter as lodashFilter,} from 'lodash';import Promise from 'bluebird';import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';@@ -25,7 +26,9 @@ import {} from '../modules/notifications/constants';import { clearCustoms, refreshPalettes } from '../modules/palettes/actions';import { clearRotate, refreshRotation } from '../modules/map/actions';-import { clearGraticule, refreshGraticule } from '../modules/layers/actions';+import {+ showLayers, clearGraticule, hideLayers, refreshGraticule,+} from '../modules/layers/actions';import { notificationWarnings } from '../modules/image-download/constants';import Notify from '../components/image-download/notify';import { hasCustomPaletteInActiveProjection } from '../modules/palettes/util';@@ -33,6 +36,7 @@ import Geosearch from '../components/geosearch/geosearch';import { toggleShowGeosearch, toggleDialogVisible } from '../modules/geosearch/actions';import { isGeosearchFeatureEnabled } from '../modules/geosearch/util';import { getAllActiveLayers } from '../modules/layers/selectors';+import { hasNonDownloadableVisibleLayer, getNonDownloadableLayerWarning, getNonDownloadableLayers } from '../modules/image-download/util';Promise.config({ cancellation: true });@@ -93,9 +97,10 @@ class toolbarContainer extends Component {}getPromise(bool, type, action, title) {+ const { visibleLayersForProj } = this.props;const { notify } = this.props;if (bool) {- return notify(type, action);+ return notify(type, action, visibleLayersForProj);}return Promise.resolve(type);}@@ -110,20 +115,23 @@ class toolbarContainer extends Component {rotation,refreshStateAfterImageDownload,toggleDialogVisible,+ hasNonDownloadableLayer,+ visibleLayersForProj,} = this.props;-+ const nonDownloadableLayers = hasNonDownloadableLayer ? getNonDownloadableLayers(visibleLayersForProj) : null;const paletteStore = lodashCloneDeep(activePalettes);toggleDialogVisible(false);await this.getPromise(hasCustomPalette, 'palette', clearCustoms, 'Notice');await this.getPromise(isRotated, 'rotate', clearRotate, 'Reset rotation');await this.getPromise(hasGraticule, 'graticule', clearGraticule, 'Remove Graticule?');+ await this.getPromise(hasNonDownloadableLayer, 'layers', hideLayers, 'Remove Layers?');await openModal('TOOLBAR_SNAPSHOT',{...CUSTOM_MODAL_PROPS.TOOLBAR_SNAPSHOT,onClose: () => {refreshStateAfterImageDownload(- hasCustomPalette ? paletteStore : undefined, rotation, hasGraticule,+ hasCustomPalette ? paletteStore : undefined, rotation, hasGraticule, nonDownloadableLayers,);},},@@ -354,7 +362,7 @@ const mapStateToProps = (state) => {// Collapse when Image download / GIF / is open or measure tool activeconst snapshotModalOpen = modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT';const shouldBeCollapsed = snapshotModalOpen || measure.isActive || animation.gifActive;-+ const visibleLayersForProj = lodashFilter(activeLayersForProj, 'visible');return {faSize,notificationType: type,@@ -367,6 +375,7 @@ const mapStateToProps = (state) => {lodashGet(state, 'map.ui.selected')&& !isCompareActive,),+ hasNonDownloadableLayer: hasNonDownloadableVisibleLayer(visibleLayersForProj),isCompareActive,isGeosearchExpanded,isMobile,@@ -375,6 +384,7 @@ const mapStateToProps = (state) => {activeLayersForProj,activePalettes,),+ visibleLayersForProj,isRotated: Boolean(map.rotation !== 0),hasGraticule: Boolean(lodashGet(@@ -396,7 +406,7 @@ const mapDispatchToProps = (dispatch) => ({toggleShowGeosearch: () => {dispatch(toggleShowGeosearch());},- refreshStateAfterImageDownload: (activePalettes, rotation, isGraticule) => {+ refreshStateAfterImageDownload: (activePalettes, rotation, isGraticule, nonDownloadableLayers) => {if (activePalettes) {dispatch(refreshPalettes(activePalettes));}@@ -406,6 +416,9 @@ const mapDispatchToProps = (dispatch) => ({if (isGraticule) {dispatch(refreshGraticule(isGraticule));}+ if (nonDownloadableLayers) {+ dispatch(showLayers(nonDownloadableLayers));+ }},openModal: (key, customParams, actions) => {dispatch(openCustomContent(@@ -413,14 +426,15 @@ const mapDispatchToProps = (dispatch) => ({customParams,));},- notify: (type, action, title) => new Promise((resolve, reject, cancel) => {+ notify: (type, action, visibleLayersForProj) => new Promise((resolve, reject, cancel) => {+ const nonDownloadableLayers = type !== 'layers' ? null : getNonDownloadableLayers(visibleLayersForProj);const bodyComponentProps = {- bodyText: notificationWarnings[type],+ bodyText: type !== 'layers' ? notificationWarnings[type] : getNonDownloadableLayerWarning(nonDownloadableLayers),cancel: () => {dispatch(onToggle());},accept: () => {- dispatch(action());+ dispatch(action(nonDownloadableLayers));resolve();},};@@ -454,6 +468,8 @@ export default connect(toolbarContainer.propTypes = {activePalettes: PropTypes.object,+ hasNonDownloadableLayer: PropTypes.bool,+ visibleLayersForProj: PropTypes.array,config: PropTypes.object,faSize: PropTypes.string,hasCustomPalette: PropTypes.bool,diff --git a/web/js/modules/image-download/util.js b/web/js/modules/image-download/util.jsindex 59c77bb74..3ffe1a5d3 100644--- a/web/js/modules/image-download/util.js+++ b/web/js/modules/image-download/util.js@@ -1,6 +1,8 @@import {each as lodashEach,get as lodashGet,+ find as lodashFind,+ filter as lodashFilter,} from 'lodash';import { boundingExtent, containsCoordinate } from 'ol/extent';import util from '../../util/util';@@ -287,3 +289,53 @@ export function getPercentageFromPixel(maxDimension, dimension) {export function getPixelFromPercentage(maxDimension, percent) {return Math.round((percent / 100) * maxDimension);}++/**+ * Find if there are layers that cannot be downloaded+ * @param {Array} visibleLayers+ *+ * @return {Bool}+ */+export function hasNonDownloadableVisibleLayer(visibleLayers) {+ const notDownloadable = !!lodashFind(visibleLayers, { snapshot: false });+ return notDownloadable;+}+/**+ * Get string of layers to be removed if alert is accepted+ * @param {Array} nonDownloadableLayers+ *+ * @return {String}+ */+export function getNamesOfNondownloadableLayers(nonDownloadableLayers) {+ let names = '';+ if (nonDownloadableLayers.length) {+ nonDownloadableLayers.forEach((obj) => {+ const str = names ? `, ${obj.title || obj.id}` : obj.title || obj.id;+ names += str;+ });+ }+ return names;+}+/**+ * Get warning that shows layers that will be removed if nofication is accepted+ * @param {Array} nonDownloadableLayers+ *+ * @return {String}+ */+export function getNonDownloadableLayerWarning(nonDownloadableLayer) {+ const layerStr = getNamesOfNondownloadableLayers(nonDownloadableLayer);+ if (!layerStr) return '';+ const multiLayers = layerStr.indexOf(',') > -1;+ return multiLayers ? `The ${layerStr} layers cannot be used to take a snapshot. Would you `+ + 'like to temporarily hide these layers?' : `The ${layerStr} layer cannot be used to take a snapshot. Would you `+ + 'like to temporarily hide this layer?';+}+/**+ * Get array of layers that will be removed if nofication is accepted+ * @param {Array} visibleLayers+ *+ * @return {Array}+ */+export function getNonDownloadableLayers(visibleLayers) {+ return lodashFilter(visibleLayers, { snapshot: false });+}diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.jsindex 68109f263..d5d869e6b 100644--- a/web/js/modules/layers/actions.js+++ b/web/js/modules/layers/actions.js@@ -271,3 +271,18 @@ export function refreshGraticule() {dispatch(toggleVisibility('Graticule', true));};}++export function hideLayers(layers) {+ return (dispatch) => {+ layers.forEach((obj) => {+ dispatch(toggleVisibility(obj.id, false));+ });+ };+}+export function showLayers(layers) {+ return (dispatch) => {+ layers.forEach((obj) => {+ dispatch(toggleVisibility(obj.id, true));+ });+ };+}