Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2870 Allow users to create image snapshots of modified classification type imagery in Worldview (#5633)

Patrick Moulden0ed11baa336a
diff --git a/e2e/features/image-download/unsupported-test.spec.js b/e2e/features/image-download/unsupported-test.spec.js
index cce0c6a18..2ca858547 100644
--- a/e2e/features/image-download/unsupported-test.spec.js
+++ b/e2e/features/image-download/unsupported-test.spec.js
@@ -1,7 +1,7 @@
// @ts-check
const { test, expect } = require('@playwright/test')
const createSelectors = require('../../test-utils/global-variables/selectors')
-const { closeImageDownloadPanel, closeModal } = require('../../test-utils/hooks/wvHooks')
+const { closeModal } = require('../../test-utils/hooks/wvHooks')
const { joinUrl } = require('../../test-utils/hooks/basicHooks')
let page
@@ -28,31 +28,6 @@ test.afterAll(async () => {
await page.close()
})
-test('Custom palettes are not supported dialog', async () => {
- const { snapshotToolbarButton } = selectors
- const url = await joinUrl(startParams, '&l=MODIS_Terra_Aerosol(palette=red_1)')
- await page.goto(url)
- await closeModal(page)
- await snapshotToolbarButton.click()
- await expect(notify).toBeVisible()
-})
-
-test('Custom palettes: Cancel button', async () => {
- await cancelNotify.click()
- await expect(notify).not.toBeVisible()
- await expect(toolbarSnapshot).not.toBeVisible()
-})
-
-test('Custom palettes: OK button brings up download panel', async () => {
- const { snapshotToolbarButton } = selectors
- await snapshotToolbarButton.click()
- await expect(notify).toBeVisible()
- await acceptNotify.click()
- await expect(notify).not.toBeVisible()
- await expect(toolbarSnapshot).toBeVisible()
- await closeImageDownloadPanel(page)
-})
-
test('Rotation is not supported dialog', async () => {
const { snapshotToolbarButton } = selectors
const url = await joinUrl(startParams, '&p=arctic&r=18')
diff --git a/web/js/components/image-download/image-download-panel.js b/web/js/components/image-download/image-download-panel.js
index 8dc415a73..75b0f29a9 100644
--- a/web/js/components/image-download/image-download-panel.js
+++ b/web/js/components/image-download/image-download-panel.js
@@ -1,6 +1,8 @@
import React, { useState, useEffect } from 'react';
+import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import googleTagManager from 'googleTagManager';
+import { getActivePalettes } from '../../modules/palettes/selectors';
import {
imageSizeValid,
getDimensions,
@@ -57,6 +59,7 @@ function ImageDownloadPanel(props) {
const [currResolution, setResolution] = useState(resolution);
const [debugUrl, setDebugUrl] = useState('');
const [showGranuleWarning, setShowGranuleWarning] = useState(false);
+ const activePalettes = useSelector((state) => getActivePalettes(state, state.compare.activeString));
useEffect(() => {
const layerList = getLayers();
@@ -83,6 +86,7 @@ function ImageDownloadPanel(props) {
currFileType,
currFileType === 'application/vnd.google-earth.kmz' ? false : currIsWorldfile,
markerCoordinates,
+ activePalettes,
);
window.open(dlURL, '_blank');
diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.js
index 816fd9cd4..f55953e5f 100644
--- a/web/js/containers/toolbar.js
+++ b/web/js/containers/toolbar.js
@@ -21,7 +21,7 @@ import {
requestNotifications,
setNotifications,
} from '../modules/notifications/actions';
-import { clearCustoms, refreshPalettes } from '../modules/palettes/actions';
+import { refreshPalettes } from '../modules/palettes/actions';
import { clearRotate, refreshRotation } from '../modules/map/actions';
import {
showLayers, hideLayers,
@@ -136,7 +136,6 @@ class toolbarContainer extends Component {
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(hasNonDownloadableLayer, 'layers', hideLayers, 'Remove Layers?');
await openModal(
diff --git a/web/js/modules/image-download/util.js b/web/js/modules/image-download/util.js
index c975bb458..fd5aca40d 100644
--- a/web/js/modules/image-download/util.js
+++ b/web/js/modules/image-download/util.js
@@ -1,5 +1,4 @@
import {
- each as lodashEach,
get as lodashGet,
} from 'lodash';
import { transform } from 'ol/proj';
@@ -179,18 +178,21 @@ export function imageUtilCalculateResolution(
* @returns {array} array of layer ids
*
*/
-export function imageUtilGetLayers(products, proj) {
- const layers = [];
- lodashEach(products, (layer) => {
+export function imageUtilGetLayers(products, proj, activePalettes) {
+ const layers = products.map((layer) => {
+ let layerId = layer.id;
if (layer.downloadId) {
- layers.push(layer.downloadId);
+ layerId = layer.downloadId;
} else if (layer.projections[proj].id) {
- layers.push(layer.projections[proj].id);
+ layerId = layer.projections[proj].id;
} else if (layer.projections[proj].layer) {
- layers.push(layer.projections[proj].layer);
- } else {
- layers.push(layer.id);
+ layerId = layer.projections[proj].layer;
+ }
+ const disabled = activePalettes?.[layer.id]?.maps?.[0]?.disabled;
+ if (Array.isArray(disabled)) {
+ return `${layerId}%28disabled=${disabled.join('-')}%29`;
}
+ return layerId;
});
return layers;
}
@@ -306,7 +308,7 @@ export function getTruncatedGranuleDates(layerDefs) {
* @param {Boolean} isWorldfile
* @param {Array} markerCoordinates
*/
-export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime, fileType, isWorldfile, markerCoordinates) {
+export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime, fileType, isWorldfile, markerCoordinates, activePalettes) {
const { crs } = proj.selected;
const {
layersArray,
@@ -314,7 +316,7 @@ export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime,
opacities,
} = imageUtilProcessWrap(
fileType,
- imageUtilGetLayers(layerDefs, proj.id),
+ imageUtilGetLayers(layerDefs, proj.id, activePalettes),
imageUtilGetLayerWrap(layerDefs),
imageUtilGetLayerOpacities(layerDefs),
);
@@ -323,6 +325,7 @@ export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime,
const { height, width } = dimensions;
const snappedDateTime = getLatestIntervalTime(layerDefs, dateTime);
const granuleDates = getTruncatedGranuleDates(layerDefs).value;
+ const colormaps = layerDefs.map((layer) => layer.palette?.id);
const params = [
'REQUEST=GetSnapshot',
`TIME=${util.toISOStringSeconds(snappedDateTime)}`,
@@ -334,6 +337,9 @@ export function getDownloadUrl(url, proj, layerDefs, bbox, dimensions, dateTime,
`WIDTH=${width}`,
`HEIGHT=${height}`,
];
+ if (Array.isArray(colormaps) && colormaps.length > 0) {
+ params.push(`colormaps=${colormaps.join(',')}`);
+ }
if (granuleDates.length > 0) {
params.push(`granule_dates=${granuleDates}`);
}
diff --git a/web/js/modules/image-download/util.test.js b/web/js/modules/image-download/util.test.js
index f791c7a49..e422b96b9 100644
--- a/web/js/modules/image-download/util.test.js
+++ b/web/js/modules/image-download/util.test.js
@@ -218,7 +218,7 @@ test('Download URL [imagedownload-url]', () => {
{ id: 1, longitude: 2.7117, latitude: -19.1609 },
{ id: 2, longitude: 71.173, latitude: -39.0961 },
];
- const dlURL = getDownloadUrl(url, proj, mockLayerDefs, lonlats, dimensions, dateTime, false, false, locationMarkers);
+ const dlURL = getDownloadUrl(url, proj, mockLayerDefs, lonlats, dimensions, dateTime, false, false, locationMarkers, undefined);
const expectedURL = 'http://localhost:3002/api/v1/snapshot'
+ '?REQUEST=GetSnapshot'
+ '&TIME=2019-06-24T00:00:00Z'
@@ -228,6 +228,7 @@ test('Download URL [imagedownload-url]', () => {
+ '&WRAP=day'
+ '&FORMAT=image/jpeg'
+ '&WIDTH=300&HEIGHT=300'
+ + '&colormaps='
+ '&MARKER=2.7117,-19.1609,71.173,-39.0961';
expect(dlURL.includes(expectedURL)).toBe(true);
});
diff --git a/web/js/modules/palettes/selectors.js b/web/js/modules/palettes/selectors.js
index e3962bdba..bc37141fe 100644
--- a/web/js/modules/palettes/selectors.js
+++ b/web/js/modules/palettes/selectors.js
@@ -504,3 +504,7 @@ export function isPaletteAllowed(layerId, config) {
}
return Boolean(config.layers[layerId].palette);
}
+
+export function getActivePalettes (state, activeString) {
+ return state.palettes[activeString];
+}