Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Fix custom colormap problems #1755"

Benjamin King3834098a55f8
diff --git a/web/js/containers/modal.js b/web/js/containers/modal.js
index 97563500c..9257752b4 100644
--- a/web/js/containers/modal.js
+++ b/web/js/containers/modal.js
@@ -132,7 +132,6 @@ class ModalContainer extends Component {
}
function mapStateToProps(state) {
- const { models } = state.legacy;
const {
bodyText,
headerText,
@@ -155,9 +154,6 @@ function mapStateToProps(state) {
headerText,
isCustom,
id,
- models,
- screenWidth: state.browser.screenWidth,
- screenHeight: state.browser.screenHeight,
bodyTemplate,
isTemplateModal,
customProps
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index 9df037211..d2e96e68c 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -11,6 +11,7 @@ import {
} from './constants';
import {
SET_CUSTOM as SET_CUSTOM_PALETTE,
+ CLEAR_CUSTOM as CLEAR_CUSTOM_PALETTE,
SET_RANGE_AND_SQUASH
} from '../palettes/constants';
import { resetLayers } from './selectors';
@@ -77,6 +78,20 @@ export function layerReducer(state = initialState, action) {
}
}
});
+ case CLEAR_CUSTOM_PALETTE:
+ layerIndex = lodashFindIndex(state[layerGroupStr], {
+ id: action.layerId
+ });
+
+ return update(state, {
+ [layerGroupStr]: {
+ [layerIndex]: {
+ custom: {
+ $set: undefined
+ }
+ }
+ }
+ });
case SET_CUSTOM_PALETTE:
layerIndex = lodashFindIndex(state[layerGroupStr], {
id: action.layerId
@@ -85,7 +100,7 @@ export function layerReducer(state = initialState, action) {
[layerGroupStr]: {
[layerIndex]: {
custom: {
- $set: action.paletteId
+ $set: [action.paletteId]
}
}
}
diff --git a/web/js/modules/palettes/actions.js b/web/js/modules/palettes/actions.js
index 4e2e42acc..d8aba74fa 100644
--- a/web/js/modules/palettes/actions.js
+++ b/web/js/modules/palettes/actions.js
@@ -96,16 +96,20 @@ export function setCustom(layerId, paletteId, index, groupName) {
*/
export function clearCustom(layerId, index, groupName) {
return (dispatch, getState) => {
- const { palettes } = getState();
+ const state = getState();
+ const { palettes } = state;
const newActivePalettesObj = clearCustomSelector(
layerId,
index,
- palettes[groupName]
+ palettes[groupName],
+ state
);
dispatch({
type: CLEAR_CUSTOM,
- groupName: groupName,
+ groupName,
+ layerId,
+ activeString: groupName,
palettes: newActivePalettesObj
});
};
diff --git a/web/js/modules/palettes/reducers.js b/web/js/modules/palettes/reducers.js
index f74e534c7..0a9f42e65 100644
--- a/web/js/modules/palettes/reducers.js
+++ b/web/js/modules/palettes/reducers.js
@@ -5,7 +5,8 @@ import {
REQUEST_PALETTE_START,
SET_RANGE_AND_SQUASH,
LOADED_CUSTOM_PALETTES,
- BULK_PALETTE_RENDERING_SUCCESS
+ BULK_PALETTE_RENDERING_SUCCESS,
+ CLEAR_CUSTOM
} from './constants';
import update from 'immutability-helper';
import util from '../../util/util';
@@ -52,13 +53,17 @@ export function paletteReducer(state = defaultPaletteState, action) {
return lodashAssign({}, state, {
[groupName]: action.palettes
});
+ case CLEAR_CUSTOM:
+ return lodashAssign({}, state, {
+ [groupName]: action.palettes || {}
+ });
case SET_CUSTOM:
return lodashAssign({}, state, {
- [groupName]: action.palettes
+ [groupName]: action.palettes || {}
});
case LOADED_CUSTOM_PALETTES:
return lodashAssign({}, state, {
- custom: action.custom
+ custom: action.custom || {}
});
default:
return state;
diff --git a/web/js/modules/palettes/selectors.js b/web/js/modules/palettes/selectors.js
index 0544b6a09..cf703d9a1 100644
--- a/web/js/modules/palettes/selectors.js
+++ b/web/js/modules/palettes/selectors.js
@@ -112,7 +112,6 @@ export function getCustomPalette(paletteId, customsPaletteConfig) {
var useLookup = function(layerId, palettesObj, state) {
var use = false;
var active = palettesObj[layerId].maps;
-
lodashEach(active, function(palette, index) {
if (palette.custom) {
use = true;
@@ -245,8 +244,8 @@ export function setCustom(layerId, paletteId, index, groupName, state) {
index = lodashIsUndefined(index) ? 0 : index;
var active = newPalettes[layerId];
var palette = active.maps[index];
- if (palette.custom === paletteId) {
- return;
+ if (palette.custom === paletteId && palette.lookup) {
+ return newPalettes;
}
palette.custom = paletteId;
return updateLookup(layerId, newPalettes, state);
@@ -311,7 +310,7 @@ export function setRange(layerId, props, index, palettes, state) {
return updateLookup(layerId, newPalettes, state);
}
-export function clearCustom(layerId, index, palettes) {
+export function clearCustom(layerId, index, palettes, state) {
index = lodashIsUndefined(index) ? 0 : index;
var active = palettes[layerId];
if (!active) {
@@ -321,7 +320,11 @@ export function clearCustom(layerId, index, palettes) {
if (!palette.custom) {
return palettes;
}
- return update(palettes, { layerId: { maps: { $unset: ['custom'] } } }); // remove custom key
+ delete palette.custom;
+ let newPalettes = update(palettes, {
+ [layerId]: { maps: { [index]: { $set: palette } } }
+ }); // remove custom key
+ return updateLookup(layerId, newPalettes, state);
}
var prepare = function(layerId, palettesObj, state) {
var newPalettes = lodashCloneDeep(palettesObj);
diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.js
index 2b691c382..27ef2ca5e 100644
--- a/web/js/modules/palettes/util.js
+++ b/web/js/modules/palettes/util.js
@@ -3,7 +3,8 @@ import {
each as lodashEach,
find as lodashFind,
assign as lodashAssign,
- isEmpty as lodashIsEmpty,
+ get as lodashGet,
+ size as lodashSize,
isArray
} from 'lodash';
import { PALETTE_STRINGS_PERMALINK_ARRAY } from './constants';
@@ -15,7 +16,6 @@ import {
} from './selectors';
import util from '../../util/util';
import Promise from 'bluebird';
-import { setFromArray } from 'ol/transform';
export function getCheckerboard() {
var size = 2;
@@ -165,7 +165,7 @@ export function getPaletteAttributeArray(layerId, palettes, state) {
let attrArray = [];
for (var i = 0; i < count; i++) {
let paletteDef = palettes[layerId].maps[i];
- let entryLength = paletteDef.entries.values.length;
+ let entryLength = lodashSize(lodashGet(paletteDef, 'entries.values')) || lodashSize(lodashGet(paletteDef, 'entries.colors'));
let maxValue = paletteDef.max
? paletteDef.entries.values[paletteDef.max || entryLength]
: undefined;
diff --git a/web/js/modules/projection/util.js b/web/js/modules/projection/util.js
index d0a14d531..f4e28fe74 100644
--- a/web/js/modules/projection/util.js
+++ b/web/js/modules/projection/util.js
@@ -6,7 +6,6 @@ export function getProjInitialState(config) {
config,
`projections.${config.defaults.projection}`
);
- console.log('selected' + selected);
return {
id: selected ? selected.id : 'geographic',
selected: selected || {}