Interactive interface for browsing global, full-resolution satellite imagery
WV-4145: Snapshot Warnings (#6993)
christof-wittreichb6fc3f729509
diff --git a/web/js/components/image-download/image-download-panel.js b/web/js/components/image-download/image-download-panel.jsindex 29a71f359..43e8819ad 100644--- a/web/js/components/image-download/image-download-panel.js+++ b/web/js/components/image-download/image-download-panel.js@@ -2,10 +2,11 @@ import { useState, useEffect, useRef } from 'react';import { connect } from 'react-redux';import PropTypes from 'prop-types';import googleTagManager from 'googleTagManager';-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';import {imageSizeValid,estimateMaxImageSize,+ calculateScaleFactor,+ calculateScaledResolution,getDimensions,getTruncatedGranuleDates,GRANULE_LIMIT,@@ -21,7 +22,8 @@ import WaitOverlay from './wait';import SnapshotError from './snapshot-error';import onClickFeedback from '../../modules/feedback/util';import initFeedback from '../../modules/feedback/actions';-import { subdailyLayersActive } from '../../modules/layers/selectors';+import { getAnyOverZoom as getAnyOverZoomAction, subdailyLayersActive } from '../../modules/layers/selectors';+import ImageDownloadWarning from './image-download-warning';const RESOLUTION_KEY = {0.075: '7.5cm',@@ -65,6 +67,7 @@ function ImageDownloadPanel(props) {sendFeedback,onResolutionChange,onProgressChange,+ getAnyOverZoom,} = props;const [currFileType, setFileType] = useState(fileType);@@ -280,6 +283,24 @@ function ImageDownloadPanel(props) {const filetypeSelect = renderFileTypeSelect();const worldfileSelect = renderWorldfileSelect();const layerList = getLayers();+ const isValidSize = imageSizeValid({+ maxHeight,+ maxWidth,+ map,+ resolution: Number(currResolution),+ pixelBbox: boundaries,+ });+ const view = map.getView();+ const viewResolution = view.getResolution();+ const scaleFactor = calculateScaleFactor(+ Number(currResolution),+ view.getProjection(),+ viewResolution,+ view.getCenter(),+ );+ const scaledResolution = calculateScaledResolution(viewResolution, scaleFactor);+ const scaledZoom = view.getZoomForResolution(scaledResolution);+ const isOverZoomed = getAnyOverZoom(scaledZoom);return (<>@@ -330,42 +351,45 @@ function ImageDownloadPanel(props) {height={height}fileSize={(((width * height) ** 0.89) * 6.88 / 8388608).toFixed(2)}maxImageSize={`${maxWidth}px x ${maxHeight}px`}- validSize={imageSizeValid({- maxHeight,- maxWidth,- map,- resolution: Number(currResolution),- pixelBbox: boundaries,- })}+ validSize={isValidSize}validLayers={layerList.length > 0}onClick={onDownload}isSnapshotInProgress={isSnapshotInProgress}/><hr />- <p className="wv-snapshot-warning">- <span className="wv-snapshot-warning-icon">- <FontAwesomeIcon- icon="exclamation-triangle"- className="wv-alert-icon"- size="1x"- widthAuto- />- </span>- This snapshot feature has been upgraded to capture anything on the map,- including customized color palettes. If you notice any issues, please- {' '}- <span- className="snapshot-feedback"- role="link"- tabIndex={0}- onKeyDown={(e, feedbackIsInitiatedArg, isMobileArg) =>- handleKeyDown(e, feedbackIsInitiatedArg, isMobileArg)}- onClick={() => sendFeedback(feedbackIsInitiated, isMobile)}- >- contact us- </span>- .- </p>+ {!isValidSize && (+ <ImageDownloadWarning+ type={'error'}+ message={'Selected bounding box and resolution are too large. Adjust bounding box size and/or resolution.'}+ />+ )}+ {isOverZoomed && isValidSize && (+ <ImageDownloadWarning+ type={'warning'}+ message={'The zoom level set for this data may result in a poor quality snapshot.'}+ />+ )}+ <ImageDownloadWarning+ type={'info'}+ message={+ <>+ This snapshot feature has been upgraded to capture anything on the map,+ including customized color palettes. If you notice any issues, please+ {' '}+ <span+ className="snapshot-feedback"+ role="link"+ tabIndex={0}+ onKeyDown={(e, feedbackIsInitiatedArg, isMobileArg) =>+ handleKeyDown(e, feedbackIsInitiatedArg, isMobileArg)}+ onClick={() => sendFeedback(feedbackIsInitiated, isMobile)}+ >+ contact us+ </span>+ .+ </>+ }+ /></div></>);@@ -379,6 +403,7 @@ const mapStateToProps = (state) => {feedbackIsInitiated: feedback.isInitiated,isMobile: screenSize.isMobileDevice,isSubdaily: subdailyLayersActive(state),+ getAnyOverZoom: (zoom) => getAnyOverZoomAction(state, zoom),};};@@ -445,4 +470,5 @@ ImageDownloadPanel.propTypes = {sendFeedback: PropTypes.func,onResolutionChange: PropTypes.func,onProgressChange: PropTypes.func,+ getAnyOverZoom: PropTypes.func,};diff --git a/web/js/components/image-download/image-download-panel.test.js b/web/js/components/image-download/image-download-panel.test.jsindex 336e0d1b8..44965e8b3 100644--- a/web/js/components/image-download/image-download-panel.test.js+++ b/web/js/components/image-download/image-download-panel.test.js@@ -25,6 +25,8 @@ global.ResizeObserver = jest.fn().mockImplementation(() => ({jest.mock('../../modules/image-download/util', () => ({imageSizeValid: jest.fn(() => true),estimateMaxImageSize: jest.fn(() => ({ width: 8192, height: 8192 })),+ calculateScaleFactor: jest.fn(() => 2),+ calculateScaledResolution: jest.fn(() => 1),getDimensions: jest.fn(() => ({ width: 10, height: 20 })),getDownloadUrl: jest.fn((url) => `${url}?download=true`),getTruncatedGranuleDates: jest.fn(() => ({ truncated: true })),@@ -85,6 +87,13 @@ describe('ImageDownloadPanel', () => {datelineMessage: 'Crosses dateline',map: {getLayers: () => ({ getArray: () => [{ wv: { id: 'L1', granuleDates: [] } }] }),+ getView: () => ({+ getProjection: () => ({ getUnits: () => 'degrees', getMetersPerUnit: () => 111000 }),+ getCenter: () => [0, 0],+ getResolution: () => 1000,+ getZoom: () => 5,+ getZoomForResolution: () => 1,+ }),},viewExtent: null,resolutions: ['1', '2'],@@ -92,6 +101,7 @@ describe('ImageDownloadPanel', () => {onLatLongChange: jest.fn(),onResolutionChange: jest.fn(),onProgressChange: jest.fn(),+ getAnyOverZoom: jest.fn(() => false),};beforeEach(() => {diff --git a/web/js/components/image-download/image-download-warning.js b/web/js/components/image-download/image-download-warning.jsnew file mode 100644index 000000000..5265e8f90--- /dev/null+++ b/web/js/components/image-download/image-download-warning.js@@ -0,0 +1,27 @@+import PropTypes from 'prop-types';+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';++function ImageDownloadWarning(props) {+ const { type, message } = props;+ const iconClass = `wv-alert-icon image-download-${type}-icon`;+ return (+ <p className="wv-snapshot-warning">+ <span className="wv-snapshot-warning-icon" data-testid={`image-download-${type}-container`}>+ <FontAwesomeIcon+ icon="exclamation-triangle"+ className={iconClass}+ size="1x"+ widthAuto+ />+ </span>+ {message}+ </p>+ );+}++ImageDownloadWarning.propTypes = {+ type: PropTypes.string,+ message: PropTypes.string,+};++export default ImageDownloadWarning;diff --git a/web/js/components/image-download/image-download-warning.test.js b/web/js/components/image-download/image-download-warning.test.jsnew file mode 100644index 000000000..17d2853fb--- /dev/null+++ b/web/js/components/image-download/image-download-warning.test.js@@ -0,0 +1,46 @@+/* eslint-disable react/jsx-props-no-spreading */+import { render, screen } from '@testing-library/react';+import '@testing-library/jest-dom';+import ImageDownloadWarning from './image-download-warning';++describe('ImageDownloadWarning Component', () => {+ const defaultProps = {+ message: 'Test warning message',+ };++ beforeEach(() => {+ jest.clearAllMocks();+ });++ test('renders without crashing', () => {+ render(<ImageDownloadWarning {...defaultProps} />);+ expect(screen.getByText('Test warning message')).toBeInTheDocument();+ });++ test('displays the message prop', () => {+ const message = 'This is a test warning';+ render(<ImageDownloadWarning {...defaultProps} message={message} />);+ expect(screen.getByText(message)).toBeInTheDocument();+ });++ test('displays the message prop (info)', () => {+ const type = 'info';+ render(<ImageDownloadWarning {...defaultProps} type={type} />);+ const infoIconContainer = screen.getByTestId(`image-download-${type}-container`);+ expect(infoIconContainer).toBeInTheDocument();+ });++ test('displays the message prop (warning)', () => {+ const type = 'warning';+ render(<ImageDownloadWarning {...defaultProps} type={type} />);+ const infoIconContainer = screen.getByTestId(`image-download-${type}-container`);+ expect(infoIconContainer).toBeInTheDocument();+ });++ test('displays the message prop (error)', () => {+ const type = 'error';+ render(<ImageDownloadWarning {...defaultProps} type={type} />);+ const infoIconContainer = screen.getByTestId(`image-download-${type}-container`);+ expect(infoIconContainer).toBeInTheDocument();+ });+});diff --git a/web/js/modules/image-download/util.js b/web/js/modules/image-download/util.jsindex f9e518eff..7bda67c56 100644--- a/web/js/modules/image-download/util.js+++ b/web/js/modules/image-download/util.js@@ -343,7 +343,7 @@ export function getTruncatedGranuleDates(layerDefs) {* @param {Array} center - Map center coordinates* @returns {Number} - Scale factor to apply to map*/-function calculateScaleFactor(targetMetersPerPixel, projection, mapResolution, center) {+export function calculateScaleFactor(targetMetersPerPixel, projection, mapResolution, center) {const currentResolutionInMeters = convertResolutionToMetersPerPixel(mapResolution,projection,@@ -354,6 +354,16 @@ function calculateScaleFactor(targetMetersPerPixel, projection, mapResolution, creturn evaluate(`${currentResolutionInMeters} / ${targetMetersPerPixel}`);}+/**+ * Calculate scaled resolution from starting resolution and scale factor+ * @param {Number} mapResolution - Current map resolution+ * @param {Number} scaleFactor - Factor to scale by+ * @returns {Number} - Scaled resolution+ */+export function calculateScaledResolution(mapResolution, scaleFactor) {+ return evaluate(`${mapResolution} / ${scaleFactor}`);+}+export const estimateMaxCanvasSize = () => canvasSize.maxArea();export async function estimateMaxImageSize() {diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.jsindex a34ecdb88..e9c971566 100644--- a/web/js/modules/layers/selectors.js+++ b/web/js/modules/layers/selectors.js@@ -863,6 +863,24 @@ export function getZotsForActiveLayers(state) {return zotObj;}+export function getAnyOverZoom(state, zoom) {+ const {+ config, proj,+ } = state;+ let isOverZoomed = false;+ const { sources } = config;+ const projection = proj.selected.id;+ lodashEach(getActiveLayersMap(state), (layer) => {+ if (layer.projections[projection]) {+ const overZoomValue = getZoomLevel(layer, zoom, projection, sources);+ if (overZoomValue) {+ isOverZoomed = true;+ }+ }+ });+ return isOverZoomed;+}+export function getMaxZoomLevelLayerCollection(layers, zoom, proj, sources) {const zoomOffset = proj === 'arctic' || proj === 'antarctic' ? 1 : 0;let maxZoom;diff --git a/web/js/modules/layers/selectors.test.js b/web/js/modules/layers/selectors.test.jsindex f22ac0dd7..29f63121c 100644--- a/web/js/modules/layers/selectors.test.js+++ b/web/js/modules/layers/selectors.test.js@@ -25,6 +25,7 @@ import {getSmallestIntervalValue,activateLayersForEventCategory,getZotsForActiveLayers,+ getAnyOverZoom,getMaxZoomLevelLayerCollection,} from './selectors';@@ -1329,6 +1330,27 @@ test('returns entries for multiple layers with independent zot conditions', () =expect(result['layer-c']).toBeUndefined();});+test('returns false when no layers are active', () => {+ const state = getZotState({ activeLayers: [] });+ expect(getAnyOverZoom(state, 5)).toEqual(false);+});++test('returns false when not overzoomed', () => {+ const layer = makeSimpleLayer('terra-aod');+ const state = getZotState({ activeLayers: [layer] });+ const result = getAnyOverZoom(state, 3);+ expect(result).toEqual(false);+});++test('returns true when overzoomed', () => {+ const resolutionCount = 4; // zoomLimit = 3+ const layer = makeZoomableLayer('terra-aod', resolutionCount);+ const sources = makeZoomableSources(resolutionCount);+ const state = getZotState({ activeLayers: [layer], sources });+ const result = getAnyOverZoom(state, 5);+ expect(result).toEqual(true);+});+test('returns fallback zoom when layers array is empty', () => {expect(getMaxZoomLevelLayerCollection([], 8, 'geographic', {})).toBe(8);});diff --git a/web/scss/components/image.scss b/web/scss/components/image.scssindex 862f74227..547afbc30 100644--- a/web/scss/components/image.scss+++ b/web/scss/components/image.scss@@ -162,6 +162,14 @@.wv-snapshot-warning-icon {font-size: 1.2em;margin-right: 8px;++ .image-download-warning-icon {+ color: #ffd445;+ }++ .image-download-error-icon {+ color: #ff5c59;+ }}.snapshot-feedback {