Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add disable all

Ben Kinge2f49a16c984
diff --git a/web/css/switch.css b/web/css/switch.css
index 33bbafe43..a69abc2dd 100644
--- a/web/css/switch.css
+++ b/web/css/switch.css
@@ -2,6 +2,13 @@
display: flex;
margin-bottom: 7px;
}
+.react-switch.header {
+ margin-bottom: 14px;
+ flex-direction: row-reverse;
+ .switch-label-text {
+ font-size: 14px;
+ }
+}
.react-switch .switch-col {
align-items: flex-start;
display: flex;
diff --git a/web/js/components/layer/settings/classification-toggle.js b/web/js/components/layer/settings/classification-toggle.js
index e2849ce07..18b3efc49 100644
--- a/web/js/components/layer/settings/classification-toggle.js
+++ b/web/js/components/layer/settings/classification-toggle.js
@@ -1,16 +1,35 @@
-import React from 'react';
+import React, { useState } from 'react';
import PropTypes from 'prop-types';
+import lodashGet from 'lodash/get';
import Switch from '../../util/switch';
import Scrollbar from '../../util/scrollbar';
-export default function ClassificationToggle (props) {
+
+export default function ClassificationToggle(props) {
const {
- legend, toggle, palette, height,
+ legend, toggle, palette, height, toggleAll,
} = props;
+ const switchLength = legend.colors.length;
+
+ const [isEnableAllSelected, toggleEnableAll] = useState((lodashGet(palette, 'disabled.length') === switchLength) && switchLength);
+
const { tooltips } = legend;
+
+
return (
<div className="layer-classification-toggle settings-component">
- <h2 className="wv-header">Disable/Enable</h2>
+ <Switch
+ id="header-disable"
+ key="header-disable"
+ label="Disable/Enable"
+ containerClassAddition="header"
+ active={!isEnableAllSelected}
+ toggle={() => {
+ const arrayOfIndices = !isEnableAllSelected ? [...Array(switchLength).keys()] : [];
+ toggleAll(arrayOfIndices);
+ toggleEnableAll(!isEnableAllSelected);
+ }}
+ />
<Scrollbar style={{ maxHeight: `${height}px` }}>
{legend.colors.map((color, index) => {
const id = legend.id + index;
@@ -37,4 +56,5 @@ ClassificationToggle.propTypes = {
legend: PropTypes.object,
palette: PropTypes.object,
toggle: PropTypes.func,
+ toggleAll: PropTypes.func,
};
diff --git a/web/js/components/layer/settings/settings.js b/web/js/components/layer/settings/settings.js
index 5b4eac0b9..daf142f11 100644
--- a/web/js/components/layer/settings/settings.js
+++ b/web/js/components/layer/settings/settings.js
@@ -28,6 +28,7 @@ import {
setCustomPalette,
clearCustomPalette,
setToggledClassification,
+ refreshDisabledClassification,
} from '../../../modules/palettes/actions';
import {
setFilterRange,
@@ -70,6 +71,7 @@ class LayerSettings extends React.Component {
setThresholdRange,
layer,
toggleClassification,
+ toggleAllClassification,
screenHeight,
} = this.props;
const { activeIndex } = this.state;
@@ -96,7 +98,13 @@ class LayerSettings extends React.Component {
if (legend.type === 'classification' && legend.colors.length > 1) {
paneItemEl = (
<TabPane key={`${legend.id}pane`} tabId={i}>
- <ClassificationToggle height={Math.ceil(screenHeight / 3)} palette={palette} toggle={(classIndex) => toggleClassification(layer.id, classIndex, i, groupName)} legend={legend} />
+ <ClassificationToggle
+ height={Math.ceil(screenHeight / 3)}
+ palette={palette}
+ toggle={(classIndex) => toggleClassification(layer.id, classIndex, i, groupName)}
+ legend={legend}
+ toggleAll={(disabledArray) => { toggleAllClassification(layer.id, disabledArray, i, groupName); }}
+ />
</TabPane>
);
} else if (
@@ -176,6 +184,7 @@ class LayerSettings extends React.Component {
groupName,
layer,
toggleClassification,
+ toggleAllClassification,
screenHeight,
} = this.props;
const paletteLegends = getPaletteLegends(layer.id);
@@ -189,7 +198,15 @@ class LayerSettings extends React.Component {
if (len > 1) {
return this.renderMultiColormapCustoms(paletteLegends);
} if (legend.type === 'classification' && legend.colors.length > 1) {
- return (<ClassificationToggle height={Math.ceil(screenHeight / 2)} palette={palette} toggle={(classIndex) => toggleClassification(layer.id, classIndex, 0, groupName)} legend={legend} />);
+ return (
+ <ClassificationToggle
+ height={Math.ceil(screenHeight / 2)}
+ palette={palette}
+ toggle={(classIndex) => toggleClassification(layer.id, classIndex, 0, groupName)}
+ legend={legend}
+ toggleAll={(disabledArray) => { toggleAllClassification(layer.id, disabledArray, 0, groupName); }}
+ />
+ );
}
return (
<>
@@ -320,6 +337,12 @@ const mapDispatchToProps = (dispatch) => ({
setToggledClassification(layerId, classIndex, index, groupName),
);
},
+ toggleAllClassification: (layerId, disabledArray, index, groupName) => {
+ console.log(disabledArray);
+ dispatch(
+ refreshDisabledClassification(layerId, disabledArray, index, groupName),
+ );
+ },
setThresholdRange: (layerId, min, max, squash, index, groupName) => {
dispatch(
setThresholdRangeAndSquash(layerId, { min, max, squash }, index, groupName),
@@ -376,5 +399,6 @@ LayerSettings.propTypes = {
setStyle: PropTypes.func,
setThresholdRange: PropTypes.func,
toggleClassification: PropTypes.func,
+ toggleAllClassification: PropTypes.func,
vectorStyles: PropTypes.object,
};
diff --git a/web/js/components/util/switch.js b/web/js/components/util/switch.js
index d65f35322..6855cdaff 100644
--- a/web/js/components/util/switch.js
+++ b/web/js/components/util/switch.js
@@ -27,7 +27,7 @@ const Switch = (props) => {
toggleActive(active);
}, [active]);
- function toggleSwitch () {
+ function toggleSwitch() {
// wait for css animation to complete before firing action
setTimeout(toggle, 200);
toggleActive(!isActive);
@@ -90,4 +90,5 @@ Switch.propTypes = {
toggle: PropTypes.func,
tooltip: PropTypes.object,
};
+
export default Switch;