Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Account for missing legacy params #1834

Benjamin Kingc80004130b4e
diff --git a/web/js/fixtures.js b/web/js/fixtures.js
index 541de10ab..78b1a7a79 100644
--- a/web/js/fixtures.js
+++ b/web/js/fixtures.js
@@ -70,52 +70,52 @@ fixtures.getState = function() {
vectorStyles: {
custom: {
OrbitTracks_Aura_Ascending: {
- 'version': 8,
- 'name': 'Orbit Tracks',
- 'sources': {
- 'OrbitTracks_Aqua_Ascending': {
- 'type': 'vector',
- 'tiles': [
+ version: 8,
+ name: 'Orbit Tracks',
+ sources: {
+ OrbitTracks_Aqua_Ascending: {
+ type: 'vector',
+ tiles: [
'https://gibs.earthdata.nasa.gov/wmts/epsg4326/nrt/OrbitTracks_Aqua_Ascending/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.mvt'
]
},
- 'yellow1': {
- 'type': 'vector',
- 'tiles': [
+ yellow1: {
+ type: 'vector',
+ tiles: [
'https://gibs.earthdata.nasa.gov/wmts/epsg4326/nrt/OrbitTracks_Aqua_Ascending/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.mvt'
]
}
},
- 'layers': [
+ layers: [
{
- 'id': 'OrbitTracks_Aqua_Ascending',
- 'source': 'OrbitTracks_Aqua_Ascending',
+ id: 'OrbitTracks_Aqua_Ascending',
+ source: 'OrbitTracks_Aqua_Ascending',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Default',
- 'type': 'line',
- 'paint': {
+ type: 'line',
+ paint: {
'line-color': 'rgb(21, 192, 230)',
'line-width': 2
}
},
{
- 'id': 'OrbitTracks_Aqua_Ascending',
- 'source': 'OrbitTracks_Aqua_Ascending',
+ id: 'OrbitTracks_Aqua_Ascending',
+ source: 'OrbitTracks_Aqua_Ascending',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Default',
- 'type': 'circle',
- 'paint': {
+ type: 'circle',
+ paint: {
'circle-radius': '5',
'circle-color': 'rgb(21, 192, 230)'
}
},
{
- 'id': 'OrbitTracks_Aqua_Ascending',
- 'source': 'OrbitTracks_Aqua_Ascending',
+ id: 'OrbitTracks_Aqua_Ascending',
+ source: 'OrbitTracks_Aqua_Ascending',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Default',
- 'type': 'symbol',
- 'layout': {
+ type: 'symbol',
+ layout: {
'text-field': ['get', 'label'],
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 10,
@@ -123,41 +123,41 @@ fixtures.getState = function() {
'text-letter-spacing': 0.05,
'text-offset': [-2.5, 0]
},
- 'paint': {
+ paint: {
'text-color': '#fff',
'text-halo-color': '#999',
'text-halo-width': 1
}
},
{
- 'id': 'yellow1',
- 'source': 'yellow1',
+ id: 'yellow1',
+ source: 'yellow1',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Yellow 1',
- 'type': 'line',
- 'paint': {
+ type: 'line',
+ paint: {
'line-color': 'rgb(204, 255, 51)',
'line-width': 2
}
},
{
- 'id': 'yellow1',
- 'source': 'yellow1',
+ id: 'yellow1',
+ source: 'yellow1',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Yellow 1',
- 'type': 'circle',
- 'paint': {
+ type: 'circle',
+ paint: {
'circle-radius': '5',
'circle-color': 'rgb(204, 255, 51)'
}
},
{
- 'id': 'yellow1',
- 'source': 'yellow1',
+ id: 'yellow1',
+ source: 'yellow1',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Yellow 1',
- 'type': 'symbol',
- 'layout': {
+ type: 'symbol',
+ layout: {
'text-field': ['get', 'label'],
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 10,
@@ -165,7 +165,7 @@ fixtures.getState = function() {
'text-letter-spacing': 0.05,
'text-offset': [-2.5, 0]
},
- 'paint': {
+ paint: {
'text-color': '#fff',
'text-halo-color': '#999',
'text-halo-width': 1
@@ -180,6 +180,7 @@ fixtures.getState = function() {
fixtures.config = function() {
return {
+ pageLoadTime: new Date(),
now: new Date(),
defaults: {
projection: 'geographic',
@@ -289,9 +290,7 @@ fixtures.config = function() {
type: 'vector',
tags: 'vector vectors',
group: 'overlays',
- layergroup: [
- 'vector'
- ],
+ layergroup: ['vector'],
inactive: true,
vectorStyle: {
id: 'OrbitTracks_Aqua_Ascending'
@@ -407,11 +406,7 @@ fixtures.config = function() {
IsOptional: 'False',
Title: 'Direction of travel',
DataType: 'string',
- ValueList: [
- 'Ascending',
- 'Descending',
- 'Transitional'
- ],
+ ValueList: ['Ascending', 'Descending', 'Transitional'],
Identifier: 'direction'
},
{
@@ -428,11 +423,7 @@ fixtures.config = function() {
IsOptional: 'False',
Title: 'Day/Night Flag',
DataType: 'string',
- ValueList: [
- 'Day',
- 'Night',
- 'Both'
- ],
+ ValueList: ['Day', 'Night', 'Both'],
Identifier: 'day_night'
},
{
@@ -456,52 +447,52 @@ fixtures.config = function() {
},
vectorStyles: {
OrbitTracks_Aura_Ascending: {
- 'version': 8,
- 'name': 'Orbit Tracks',
- 'sources': {
- 'OrbitTracks_Aqua_Ascending': {
- 'type': 'vector',
- 'tiles': [
+ version: 8,
+ name: 'Orbit Tracks',
+ sources: {
+ OrbitTracks_Aqua_Ascending: {
+ type: 'vector',
+ tiles: [
'https://gibs.earthdata.nasa.gov/wmts/epsg4326/nrt/OrbitTracks_Aqua_Ascending/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.mvt'
]
},
- 'yellow1': {
- 'type': 'vector',
- 'tiles': [
+ yellow1: {
+ type: 'vector',
+ tiles: [
'https://gibs.earthdata.nasa.gov/wmts/epsg4326/nrt/OrbitTracks_Aqua_Ascending/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.mvt'
]
}
},
- 'layers': [
+ layers: [
{
- 'id': 'OrbitTracks_Aqua_Ascending',
- 'source': 'OrbitTracks_Aqua_Ascending',
+ id: 'OrbitTracks_Aqua_Ascending',
+ source: 'OrbitTracks_Aqua_Ascending',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Default',
- 'type': 'line',
- 'paint': {
+ type: 'line',
+ paint: {
'line-color': 'rgb(21, 192, 230)',
'line-width': 2
}
},
{
- 'id': 'OrbitTracks_Aqua_Ascending',
- 'source': 'OrbitTracks_Aqua_Ascending',
+ id: 'OrbitTracks_Aqua_Ascending',
+ source: 'OrbitTracks_Aqua_Ascending',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Default',
- 'type': 'circle',
- 'paint': {
+ type: 'circle',
+ paint: {
'circle-radius': '5',
'circle-color': 'rgb(21, 192, 230)'
}
},
{
- 'id': 'OrbitTracks_Aqua_Ascending',
- 'source': 'OrbitTracks_Aqua_Ascending',
+ id: 'OrbitTracks_Aqua_Ascending',
+ source: 'OrbitTracks_Aqua_Ascending',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Default',
- 'type': 'symbol',
- 'layout': {
+ type: 'symbol',
+ layout: {
'text-field': ['get', 'label'],
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 10,
@@ -509,41 +500,41 @@ fixtures.config = function() {
'text-letter-spacing': 0.05,
'text-offset': [-2.5, 0]
},
- 'paint': {
+ paint: {
'text-color': '#fff',
'text-halo-color': '#999',
'text-halo-width': 1
}
},
{
- 'id': 'yellow1',
- 'source': 'yellow1',
+ id: 'yellow1',
+ source: 'yellow1',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Yellow 1',
- 'type': 'line',
- 'paint': {
+ type: 'line',
+ paint: {
'line-color': 'rgb(204, 255, 51)',
'line-width': 2
}
},
{
- 'id': 'yellow1',
- 'source': 'yellow1',
+ id: 'yellow1',
+ source: 'yellow1',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Yellow 1',
- 'type': 'circle',
- 'paint': {
+ type: 'circle',
+ paint: {
'circle-radius': '5',
'circle-color': 'rgb(204, 255, 51)'
}
},
{
- 'id': 'yellow1',
- 'source': 'yellow1',
+ id: 'yellow1',
+ source: 'yellow1',
'source-layer': 'OrbitTracks_Aqua_Ascending',
'source-description': 'Yellow 1',
- 'type': 'symbol',
- 'layout': {
+ type: 'symbol',
+ layout: {
'text-field': ['get', 'label'],
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 10,
@@ -551,7 +542,7 @@ fixtures.config = function() {
'text-letter-spacing': 0.05,
'text-offset': [-2.5, 0]
},
- 'paint': {
+ paint: {
'text-color': '#fff',
'text-halo-color': '#999',
'text-halo-width': 1
diff --git a/web/js/modules/data/util.js b/web/js/modules/data/util.js
index 27fb5dfca..9402a8f16 100644
--- a/web/js/modules/data/util.js
+++ b/web/js/modules/data/util.js
@@ -14,29 +14,32 @@ export function mapLocationToDataState(
state,
config
) {
- if (parameters.download) {
- const productId = parameters.download;
- if (productId) {
- const activeString =
- lodashGet(stateFromLocation, 'compare.activeString') ||
- lodashGet(state, 'compare.activeString');
- const activeLayers =
- lodashGet(stateFromLocation, `layers.${activeString}`) ||
- lodashGet(state, `layers.${activeString}`);
- if (
- !config.products[productId] ||
- !lodashFind(activeLayers, { product: productId })
- ) {
- console.warn('No such product: ' + productId);
+ const productId = parameters.download || parameters.dataDownload;
+ if (productId) {
+ const activeString =
+ lodashGet(stateFromLocation, 'compare.activeString') ||
+ lodashGet(state, 'compare.activeString');
+ const activeLayers =
+ lodashGet(stateFromLocation, `layers.${activeString}`) ||
+ lodashGet(state, `layers.${activeString}`);
+ if (
+ !config.products[productId] ||
+ !lodashFind(activeLayers, { product: productId })
+ ) {
+ console.warn('No such product: ' + productId);
+ stateFromLocation = update(stateFromLocation, {
+ data: { selectedProduct: { $set: '' } }
+ });
+ stateFromLocation = update(stateFromLocation, {
+ data: { active: { $set: false } }
+ });
+ } else {
+ stateFromLocation = update(stateFromLocation, {
+ data: { active: { $set: true } }
+ });
+ if (parameters.dataDownload && !parameters.download) {
stateFromLocation = update(stateFromLocation, {
- data: { selectedProduct: { $set: '' } }
- });
- stateFromLocation = update(stateFromLocation, {
- data: { active: { $set: false } }
- });
- } else {
- stateFromLocation = update(stateFromLocation, {
- data: { active: { $set: true } }
+ data: { selectedProduct: { $set: productId } }
});
}
}
diff --git a/web/js/modules/data/util.test.js b/web/js/modules/data/util.test.js
new file mode 100644
index 000000000..9dd71f53b
--- /dev/null
+++ b/web/js/modules/data/util.test.js
@@ -0,0 +1,29 @@
+import { mapLocationToDataState } from './util';
+import fixtures from '../../fixtures';
+
+const globalState = fixtures.getState();
+const config = {
+ products: {
+ product1: true
+ }
+};
+
+let defaultStateFromLocation = {};
+beforeEach(() => {
+ defaultStateFromLocation = {
+ data: {},
+ layers: { active: [{ product: 'product1' }] }
+ };
+});
+test('parses state, 1.1', () => {
+ let parameters = { dataDownload: 'product1' };
+
+ let stateFromLocation = mapLocationToDataState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ const selected = stateFromLocation.data.selectedProduct;
+ expect(selected).toBe('product1');
+});
diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.js
index 07670c5e3..72aba02d9 100644
--- a/web/js/modules/date/util.js
+++ b/web/js/modules/date/util.js
@@ -54,11 +54,13 @@ export function mapLocationToDateState(
// legacy time permalink
if (parameters.time && !parameters.t && appNow) {
const date = tryCatchDate(parameters.time, appNow);
- stateFromLocation = update(stateFromLocation, {
- date: {
- selected: { $set: date }
- }
- });
+ if (date && date !== appNow) {
+ stateFromLocation = update(stateFromLocation, {
+ date: {
+ selected: { $set: date }
+ }
+ });
+ }
}
return stateFromLocation;
}
diff --git a/web/js/modules/date/util.test.js b/web/js/modules/date/util.test.js
new file mode 100644
index 000000000..1d25fbf18
--- /dev/null
+++ b/web/js/modules/date/util.test.js
@@ -0,0 +1,35 @@
+import { mapLocationToDateState, tryCatchDate } from './util';
+import fixtures from '../../fixtures';
+const state = fixtures.getState();
+
+test('parses date 1.1', () => {
+ const d = new Date(Date.UTC(2013, 0, 5));
+ let param = {
+ time: '2013-01-05'
+ };
+ let stateFromLocation = {
+ date: {}
+ };
+
+ stateFromLocation = mapLocationToDateState(param, stateFromLocation, state);
+ expect(stateFromLocation.date.selected).toMatchObject(d);
+});
+test('parses valid date: 1.2', () => {
+ let d = new Date(Date.UTC(2013, 0, 5));
+ let param = {
+ t: '2013-01-05'
+ };
+ let date = tryCatchDate(param.t, state.date.appNow);
+ expect(date).toEqual(d);
+});
+test('If date is invalid, uses pageLoad Time', () => {
+ let param = {
+ time: 'X'
+ };
+ let stateFromLocation = {
+ date: state.date
+ };
+ stateFromLocation = mapLocationToDateState(param, stateFromLocation, state);
+
+ expect(stateFromLocation.date.selected).toBe(state.date.appNow);
+});
diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.js
index eef41e3db..7202bbc90 100644
--- a/web/js/modules/layers/util.js
+++ b/web/js/modules/layers/util.js
@@ -6,15 +6,11 @@ import {
findIndex as lodashFindIndex,
each as lodashEach,
isNaN as lodashIsNaN,
- get as lodashGet,
isArray
} from 'lodash';
import { addLayer, resetLayers } from './selectors';
-import {
- getPaletteAttributeArray,
- parseLegacyPalettes
-} from '../palettes/util';
+import { getPaletteAttributeArray } from '../palettes/util';
import { getVectorStyleAttributeArray } from '../vector-styles/util';
import update from 'immutability-helper';
import util from '../../util/util';
@@ -412,23 +408,14 @@ export function mapLocationToLayerState(
});
}
// legacy layers permalink
- if (parameters.product) {
+ if (parameters.products && !parameters.l) {
stateFromLocation = update(stateFromLocation, {
layers: {
active: {
- $set: layersParse11(state.parameters.product, config)
+ $set: layersParse11(parameters.products, config)
}
}
});
}
- // legacy palettes permalink
- if (parameters.palettes && lodashGet(stateFromLocation, 'layers.active')) {
- stateFromLocation = parseLegacyPalettes(
- parameters,
- stateFromLocation,
- state,
- config
- );
- }
return stateFromLocation;
}
diff --git a/web/js/modules/layers/util.test.js b/web/js/modules/layers/util.test.js
index 36af503b2..fe5686a85 100644
--- a/web/js/modules/layers/util.test.js
+++ b/web/js/modules/layers/util.test.js
@@ -2,11 +2,18 @@ import {
serializeLayers,
layersParse12,
removeLayer,
- toggleVisibility
+ toggleVisibility,
+ mapLocationToLayerState
} from './util';
import { initialState } from './reducers';
import fixtures from '../../fixtures';
import { assign } from 'lodash';
+let defaultStateFromLocation = {
+ layers: {
+ active: []
+ }
+};
+const globalState = fixtures.getState();
const config = fixtures.config();
const PALETTE_LAYER_STRING =
'AMSRE_Brightness_Temp_89H_Night(hidden,opacity=0.54,palette=red_2,min=224,225,max=294,295,squash=true),mask';
@@ -102,3 +109,134 @@ test('toggleVisibility util function', () => {
const newLayers = toggleVisibility('terra-cr', layers);
expect(newLayers[1].visible).toBe(true);
});
+describe('permalink 1.0', () => {
+ beforeEach(() => {
+ defaultStateFromLocation = {
+ layers: {
+ active: []
+ }
+ };
+ });
+ test('supports old style period delimiters', () => {
+ let parameters = {
+ products: 'baselayers.terra-cr~overlays.terra-aod.aqua-aod'
+ };
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ const activeLayers = stateFromLocation.layers.active;
+
+ expect(activeLayers.find(x => x.id === 'terra-cr')).toBeTruthy();
+ expect(activeLayers.find(x => x.id === 'terra-aod')).toBeTruthy();
+ expect(activeLayers.find(x => x.id === 'aqua-aod')).toBeTruthy();
+ });
+});
+
+describe('permalink 1.1', () => {
+ beforeEach(() => {
+ defaultStateFromLocation = {
+ layers: {
+ active: []
+ }
+ };
+ });
+
+ test('parses only one baselayer', () => {
+ let parameters = {
+ products: 'baselayers,terra-cr'
+ };
+
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ expect(stateFromLocation.layers.active[0].id).toBe('terra-cr');
+ });
+ test('parses only one overlay', () => {
+ let parameters = {
+ products: 'overlays,terra-aod'
+ };
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+
+ expect(stateFromLocation.layers.active[0].id).toBe('terra-aod');
+ });
+ test('parses multiple layers', () => {
+ let parameters = {
+ products: 'baselayers,terra-cr~overlays,terra-aod,aqua-aod'
+ };
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ expect(activeLayers.find(x => x.id === 'terra-cr')).toBeTruthy();
+ expect(activeLayers.find(x => x.id === 'terra-aod')).toBeTruthy();
+ expect(activeLayers.find(x => x.id === 'aqua-aod')).toBeTruthy();
+ });
+ test('empty layer list', () => {
+ let parameters = {
+ products: 'baselayers~overlays'
+ };
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ expect(activeLayers).toHaveLength(0);
+ });
+ test('skips invalid layers and records an error', () => {
+ let parameters = {
+ products: 'baselayers,terra-cr~overlays,layerx,aqua-aod'
+ };
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ expect(activeLayers.find(x => x.id === 'terra-cr')).toBeTruthy();
+ expect(activeLayers.find(x => x.id === 'aqua-aod')).toBeTruthy();
+ });
+ test('no layers if no groups found', () => {
+ let parameters = {
+ products: 'layerx,layery'
+ };
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ expect(activeLayers).toHaveLength(0);
+ });
+ test('hidden layers', () => {
+ let parameters = {
+ products: 'baselayers,!terra-cr'
+ };
+ let stateFromLocation = mapLocationToLayerState(
+ parameters,
+ defaultStateFromLocation,
+ globalState,
+ config
+ );
+ const activeLayers = stateFromLocation.layers.active;
+ expect(activeLayers[0].id).toBe('terra-cr');
+ expect(activeLayers[0].visible).toBeFalsy();
+ });
+});
diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.js
index d3923d36a..eeeac0d1a 100644
--- a/web/js/modules/palettes/util.js
+++ b/web/js/modules/palettes/util.js
@@ -137,7 +137,7 @@ export function parseLegacyPalettes(
state,
config
) {
- var parts = state.palettes.split('~');
+ var parts = parameters.palettes.split('~');
parts.forEach(part => {
var items = part.split(',');
var layerId = items[0];
@@ -380,6 +380,15 @@ export function mapLocationToPaletteState(
})
);
}
+ // legacy palettes permalink
+ if (parameters.palettes && lodashGet(stateFromLocation, 'layers.active')) {
+ stateFromLocation = parseLegacyPalettes(
+ parameters,
+ stateFromLocation,
+ state,
+ config
+ );
+ }
return stateFromLocation;
}
/**
diff --git a/web/js/modules/palettes/util.test.js b/web/js/modules/palettes/util.test.js
index 54ff15516..1f7c8f9f8 100644
--- a/web/js/modules/palettes/util.test.js
+++ b/web/js/modules/palettes/util.test.js
@@ -1,6 +1,10 @@
import update from 'immutability-helper';
import { layersParse12 } from '../layers/util';
-import { hasCustomTypePalette, loadPalettes } from './util';
+import {
+ hasCustomTypePalette,
+ loadPalettes,
+ mapLocationToPaletteState
+} from './util';
import util from '../../util/util';
import fixtures from '../../fixtures';
const state = fixtures.getState();
@@ -35,3 +39,69 @@ test('loadPalettes func updates state with correct palette attributes', () => {
expect(colorMap.custom).toEqual('red-1');
expect(colorMap.squash).toEqual(true);
});
+describe('permalink 1.1', () => {
+ test('parses palette for valid layer', () => {
+ let parameters = {
+ l: 'terra-aod',
+ palettes: 'terra-aod,blue-1'
+ };
+ let stateFromLocation = update(state, {
+ layers: { active: { $set: layersParse12(parameters.l, config) } }
+ });
+
+ stateFromLocation = mapLocationToPaletteState(
+ parameters,
+ stateFromLocation,
+ state,
+ config
+ );
+ const layer = stateFromLocation.layers.active[0];
+ expect(layer.id).toBe('terra-aod');
+ expect(layer.custom).toBe('blue-1');
+ });
+
+ test('parses palette for two valid layers', () => {
+ let parameters = {
+ l: 'terra-aod,aqua-aod',
+ palettes: 'terra-aod,blue-1~aqua-aod,red-1'
+ };
+ let stateFromLocation = update(state, {
+ layers: { active: { $set: layersParse12(parameters.l, config) } }
+ });
+ stateFromLocation = mapLocationToPaletteState(
+ parameters,
+ stateFromLocation,
+ state,
+ config
+ );
+
+ const layer1 = stateFromLocation.layers.active[0];
+ const layer2 = stateFromLocation.layers.active[1];
+ expect(layer1.id).toBe('terra-aod');
+ expect(layer1.custom).toBe('blue-1');
+
+ expect(layer2.id).toBe('aqua-aod');
+ expect(layer2.custom).toBe('red-1');
+ });
+
+ test('disregard palettes value if palette assigned to a layer that is not active', () => {
+ var parameters = {
+ l: 'terra-aod',
+ palettes: 'aqua-aod,red-1'
+ };
+ let stateFromLocation = update(state, {
+ layers: { active: { $set: layersParse12(parameters.l, config) } }
+ });
+ stateFromLocation = mapLocationToPaletteState(
+ parameters,
+ stateFromLocation,
+ state,
+ config
+ );
+ const layer = stateFromLocation.layers.active[0];
+
+ expect(layer.id).toBe('terra-aod');
+ expect(layer.custom).toBeUndefined();
+ expect(stateFromLocation.layers.active.length).toBe(1);
+ });
+});
diff --git a/web/js/modules/projection/util.js b/web/js/modules/projection/util.js
index 703a2e4b8..27f61602e 100644
--- a/web/js/modules/projection/util.js
+++ b/web/js/modules/projection/util.js
@@ -25,11 +25,23 @@ export function parseProjection(str, config) {
*/
export function mapLocationToProjState(parameters, stateFromLocation, state) {
const projId = lodashGet(stateFromLocation, 'proj.id');
- if (projId) {
- let selected = lodashGet(state, `config.projections.${projId}`) || {};
- stateFromLocation = update(stateFromLocation, {
- proj: { selected: { $set: selected } }
- });
+ if (parameters.p) {
+ let selected = lodashGet(state, `config.projections.${projId}`);
+ if (selected) {
+ stateFromLocation = update(stateFromLocation, {
+ proj: { selected: { $set: selected } }
+ });
+ }
+ } else if (parameters.switch) {
+ let id = parameters.switch;
+ let selected = lodashGet(state, `config.projections.${id}`);
+ if (selected) {
+ const newProjState = { id, selected };
+
+ stateFromLocation = update(stateFromLocation, {
+ proj: { $set: newProjState }
+ });
+ }
}
return stateFromLocation;
}
diff --git a/web/js/modules/projection/util.test.js b/web/js/modules/projection/util.test.js
index 58a11307a..22216ca62 100644
--- a/web/js/modules/projection/util.test.js
+++ b/web/js/modules/projection/util.test.js
@@ -1,5 +1,7 @@
import { mapLocationToProjState, getProjInitialState } from './util';
-
+import fixtures from '../../fixtures';
+import update from 'immutability-helper';
+const state = fixtures.getState();
const proj = {
id: 'some-test-projection'
};
@@ -41,6 +43,27 @@ test('mapLocationToProjState: Update proj:id key onload', () => {
const stateFromLocation = {
proj: proj
};
- const newState = mapLocationToProjState(null, stateFromLocation, state);
+ const newState = mapLocationToProjState({}, stateFromLocation, state);
expect(newState.proj.id).toBe('some-test-projection');
});
+
+test('legacy switch parameter for projection', () => {
+ let param = {
+ switch: 'some-test-projection'
+ };
+ let stateFromLocation = {
+ proj: proj
+ };
+ const localState = update(state, {
+ config: {
+ $set: config
+ }
+ });
+ const newStateFromLocation = mapLocationToProjState(
+ param,
+ stateFromLocation,
+ localState
+ );
+ expect(newStateFromLocation.proj.id).toBe('some-test-projection');
+ expect(newStateFromLocation.proj.selected.id).toBe('some-test-projection');
+});