Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2865 Classification/Palettes Layers Classification Toggle Behavior (#5121)

christof-wittreichfa8928dbb815
diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.js
index 7e0c3b809..f8a40ccf5 100644
--- a/web/js/components/sidebar/paletteLegend.js
+++ b/web/js/components/sidebar/paletteLegend.js
@@ -381,7 +381,7 @@ class PaletteLegend extends React.Component {
palletteClass = isInvisible ? `${palletteClass} checkerbox-bg` : palletteClass;
let legendColor = color;
const customColor = palette.custom;
- if (palette.custom !== undefined) {
+ if (palette.custom !== undefined && palette.custom !== '') {
[legendColor] = palettes.custom[customColor].colors;
}
diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.js
index 9fb1ff435..69e93fd86 100644
--- a/web/js/modules/layers/util.js
+++ b/web/js/modules/layers/util.js
@@ -846,7 +846,7 @@ export function serializeLayers(layers, state, groupName) {
value: bandComboString,
});
}
- if (def.palette && (def.custom || def.min || def.max || def.squash || def.disabled)) {
+ if (def.palette && (def.custom || def.min || def.max || def.squash || def.disabled || (palettes[def.id] && palettes[def.id].maps && palettes[def.id].maps.length > 1))) {
// If layer has palette and palette attributes
const paletteAttributeArray = getPaletteAttributeArray(
def.id,
@@ -926,7 +926,15 @@ const getLayerSpec = (attributes) => {
}
if (attr.id === 'disabled') {
const values = util.toArray(attr.value.split(';'));
- disabled = values;
+ const disabledArray = [];
+ lodashEach(values, (value, index) => {
+ if (value === '') {
+ disabledArray.push(undefined);
+ } else {
+ disabledArray.push(value);
+ }
+ });
+ disabled = disabledArray;
}
if (attr.id === 'max' && typeof attr.value === 'string') {
diff --git a/web/js/modules/palettes/selectors.js b/web/js/modules/palettes/selectors.js
index 48362bee5..28de8a46e 100644
--- a/web/js/modules/palettes/selectors.js
+++ b/web/js/modules/palettes/selectors.js
@@ -386,7 +386,7 @@ export function refreshDisabledSelector(
},
},
});
- return toggleLookup(layerId, newPalettes, state);
+ return updateLookup(layerId, newPalettes, state);
}
export function initDisabledSelector(
@@ -396,7 +396,7 @@ export function initDisabledSelector(
palettes,
state,
) {
- const disabled = disabledStr.split('-');
+ const disabled = disabledStr ? disabledStr.split('-') : [];
for (let i = 0; i < disabled.length; i += 1) { disabled[i] = +disabled[i]; }
let newPalettes = prepare(layerId, palettes, state);
newPalettes = update(newPalettes, {
@@ -441,7 +441,7 @@ export function setDisabledSelector(
},
},
});
- return toggleLookup(layerId, newPalettes, state);
+ return updateLookup(layerId, newPalettes, state);
}
export function setRange(layerId, props, index, palettes, state) {
diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.js
index 091ac1588..16fdecf4d 100644
--- a/web/js/modules/palettes/util.js
+++ b/web/js/modules/palettes/util.js
@@ -344,7 +344,7 @@ export function getPaletteAttributeArray(layerId, palettes, state) {
}
[palObj, minObj, maxObj, squashObj, disabledObj].forEach((obj) => {
- if (obj.isActive) {
+ if (obj.isActive || (obj.key === 'disabled' && obj.value !== '')) {
attrArray.push({
id: obj.key === 'custom' ? 'palette' : obj.key,
value: obj.value,
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index 247acf967..c193c0fb7 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -12,6 +12,10 @@ import { stylefunction } from 'ol-mapbox-style';
import {
getMinValue, getMaxValue, selectedStyleFunction,
} from './util';
+import {
+ isActive as isPaletteActive,
+ getLookup as getPaletteLookup,
+} from '../palettes/selectors';
import util from '../../util/util';
@@ -115,6 +119,26 @@ const updateGlStylePalette = (glStyle, rgbPalette) => {
return glStyle;
};
+const updateDisabled = (glStyle, lookup) => {
+ for (let i = 0; i < glStyle.layers.length; i += 1) {
+ const thisCircleColor = glStyle.layers[i].paint['circle-color'];
+ thisCircleColor.forEach((color, index) => {
+ const regex = /rgba?\(.*\)/;
+ if (regex.test(color)) {
+ const colors = color.split('(')[1].split(')')[0].split(/,\s?/);
+ if (colors.length < 4) {
+ colors.push('255');
+ }
+ const colorStr = colors.join(',');
+ if (lookup[colorStr]) {
+ thisCircleColor[index] = `rgba(${lookup[colorStr].r}, ${lookup[colorStr].g}, ${lookup[colorStr].b}, ${lookup[colorStr].a})`;
+ }
+ }
+ });
+ }
+ return glStyle;
+};
+
const shouldRenderFeature = (feature, acceptableExtent) => {
if (!acceptableExtent) return true;
const midpoint = feature.getFlatCoordinates
@@ -130,10 +154,11 @@ const shouldRenderFeature = (feature, acceptableExtent) => {
* @param {String} vectorStyleId | ID to lookup the vector style in the state
* @param {Object} vectorStyles | Contains styles of all vector products
* @param {Object} layer | OL layer object
+ * @param {Object} options | Layer options object
* @param {Object} state | The entire state of the application
* @param {Boolean} styleSelection | Indicates if the request is triggered by user interaction with vector feature
*/
-export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state, styleSelection = false) {
+export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, options, state, styleSelection = false) {
const map = lodashGet(state, 'map.ui.selected');
if (!map) return;
const { proj } = state;
@@ -142,6 +167,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state,
const layerId = def.id;
const styleId = lodashGet(def, `vectorStyle.${proj.id}.id`) || vectorStyleId || lodashGet(def, 'vectorStyle.id') || layerId;
const customPalette = def.custom;
+ const disabledPalette = def.disabled;
let glStyle = vectorStyles[styleId];
if (customPalette && Object.prototype.hasOwnProperty.call(state, 'palettes')) {
@@ -155,6 +181,17 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state,
}
}
+ // De-reference the glState object prior to applying the palette to the layer
+ glStyle = lodashCloneDeep(glStyle);
+
+ let lookup;
+ if (isPaletteActive(def.id, options.group, state)) {
+ lookup = getPaletteLookup(def.id, options.group, state);
+ }
+ if (disabledPalette) {
+ glStyle = updateDisabled(glStyle, lookup);
+ }
+
if (!layer || layer.isWMS || glStyle === undefined) {
return;
}
@@ -168,8 +205,6 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state,
? lodashFind(layer.getLayers().getArray(), 'isVector')
: layer;
- // De-reference the glState object prior to applying the palette to the layer
- glStyle = lodashCloneDeep(glStyle);
const styleFunction = stylefunction(layer, glStyle, layerId, resolutions);
const selectedFeatures = selected[layerId];
@@ -259,8 +294,9 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, stat
* @param {Object} def
* @param {Object} olVectorLayer
* @param {Object} state
+ * @param {Object} options
*/
-export const applyStyle = (def, olVectorLayer, state) => {
+export const applyStyle = (def, olVectorLayer, state, options) => {
const { config } = state;
const { vectorStyles } = config;
const vectorStyleId = def.vectorStyle.id;
@@ -269,5 +305,5 @@ export const applyStyle = (def, olVectorLayer, state) => {
return;
}
- setStyleFunction(def, vectorStyleId, vectorStyles, olVectorLayer, state);
+ setStyleFunction(def, vectorStyleId, vectorStyles, olVectorLayer, options, state);
};