Interactive interface for browsing global, full-resolution satellite imagery
Implement classification toggle wip #2306
Benjamin King00bb30e24adf
diff --git a/web/css/util.css b/web/css/util.cssindex ae10d1fab..47a039a1d 100644--- a/web/css/util.css+++ b/web/css/util.css@@ -9,7 +9,6 @@ button[data-tooltip] {[data-tooltip] {position: relative;}-[data-tooltip]::before,[data-tooltip]::after {-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";@@ -211,3 +210,8 @@ button[data-tooltip] {.cursor-pointer {cursor: pointer;}+.checker-board-pattern {+ background-image: linear-gradient(45deg, #808080 25%, transparent 25%), linear-gradient(-45deg, #808080 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #808080 75%), linear-gradient(-45deg, transparent 75%, #808080 75%);+ background-size: 5px 5px;+ background-position: 0 0, 0 10px, 10px -10px, -10px 0px;+}\ No newline at end of filediff --git a/web/js/components/layer/settings/classification-toggle.js b/web/js/components/layer/settings/classification-toggle.jsindex 653685517..e74ce15f8 100644--- a/web/js/components/layer/settings/classification-toggle.js+++ b/web/js/components/layer/settings/classification-toggle.js@@ -5,9 +5,17 @@ import Switch from '../../util/switch';import Scrollbar from '../../util/scrollbar';class ClassificationToggle extends React.Component {+ constructor(props) {+ super(props);+ this.state = {+ active: props.active+ };+ }render() {- const { layer, legend, toggle } = this.props;+ const { legend, toggle } = this.props;const tooltips = legend.tooltips;++return (<div className="layer-classification-toggle settings-component"><h2 className="wv-header">Category Enable/Disable</h2>@@ -15,8 +23,16 @@ class ClassificationToggle extends React.Component {{legend.colors.map((color, index) => {const id = legend.id + index;const tooltip = tooltips[index];+ const inActive = legend.disabled && legend.disabled.contains(index);return (- <Switch key={id} color={color} label={tooltip} active={true} toggle={() => toggle(index)} />+ <Switch+ id={id}+ key={id}+ color={color}+ label={tooltip}+ active={!inActive}+ toggle={() => toggle(index)}+ />);})}</Scrollbar>diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.jsindex 894cc9e03..635171ea5 100644--- a/web/js/components/sidebar/paletteLegend.js+++ b/web/js/components/sidebar/paletteLegend.js@@ -258,8 +258,8 @@ class PaletteLegend extends React.Component {{isMoreThanOneColorBar ? (<div className="wv-palettes-title">{legend.title}</div>) : (- ''- )}+ ''+ )}<div className="colorbar-case"><canvasclassName="wv-palettes-colorbar"@@ -348,13 +348,18 @@ class PaletteLegend extends React.Component {const tooltipText = singleKey? layer.track ? trackLabel : legendTooltip: keyLabel;-+ const checkerBoardPattern = {+ backgroundImage: 'linear-gradient(45deg, #808080 25%, transparent 25%), linear-gradient(-45deg, #808080 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #808080 75%), linear-gradient(-45deg, transparent 75%, #808080 75%)',+ backgroundSize: '20px 20px',+ backgroundPosition: '0 0, 0 10px, 10px -10px, -10px 0px'+ }+ console.log(color === '00000000')return (<React.Fragment key={keyId}><spanid={keyId}- className={palletteClass}- style={{ backgroundColor: util.hexToRGBA(color) }}+ className={color === '00000000' ? palletteClass + ' checker-board-pattern': palletteClass}+ style={color === '00000000' ? {} : { backgroundColor: util.hexToRGBA(color) }}onMouseMove={this.onMove.bind(this, color)}onMouseEnter={this.onMouseEnter.bind(this)}onMouseLeave={this.hideValue.bind(this)}diff --git a/web/js/components/util/switch.js b/web/js/components/util/switch.jsindex 90cba514d..9bc7e5e21 100644--- a/web/js/components/util/switch.js+++ b/web/js/components/util/switch.js@@ -1,21 +1,25 @@-import React from 'react';+import React, { useState } from 'react';// https://upmostly.com/tutorials/build-a-react-switch-toggle-componentconst Switch = (props) => {- const { color, active, toggle, label } = props;- const style = color && active ? { backgroundColor: '#' + color } : {};+ const { color, id, active, toggle, label } = props;+ const [isActive, toggleActive] = useState(active);+ const style = color && isActive ? { backgroundColor: '#' + color } : {};return (<div className='react-switch'><div className='react-switch-case switch-col'><inputclassName="react-switch-checkbox"- id={`react-switch-new`}+ id={id}type="checkbox"- checked={active}- onChange={toggle}+ checked={isActive}+ onChange={() => {+ toggle()+ toggleActive(!isActive)+ }}/><labelclassName="react-switch-label"- htmlFor={`react-switch-new`}+ htmlFor={id}style={style}><span className={`react-switch-button`} />diff --git a/web/js/map/ui.js b/web/js/map/ui.jsindex 0488d2e5e..9c9d2b0a9 100644--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@ -133,6 +133,7 @@ export function mapui(models, config, store, ui) {return updateProjection();case paletteConstants.SET_THRESHOLD_RANGE_AND_SQUASH:case paletteConstants.SET_CUSTOM:+ case paletteConstants.SET_DISABLED_CLASSIFICATION:case paletteConstants.CLEAR_CUSTOM:return updateLookup();case vectorStyleConstants.SET_FILTER_RANGE:diff --git a/web/js/modules/palettes/actions.js b/web/js/modules/palettes/actions.jsindex 9f6e039b8..1d9f9958c 100644--- a/web/js/modules/palettes/actions.js+++ b/web/js/modules/palettes/actions.js@@ -4,13 +4,15 @@ import {SET_THRESHOLD_RANGE_AND_SQUASH,CLEAR_CUSTOM,SET_CUSTOM,+ SET_DISABLED_CLASSIFICATION,LOADED_CUSTOM_PALETTES} from './constants';import { forOwn as lodashForOwn } from 'lodash';import {setRange as setRangeSelector,setCustomSelector,- clearCustomSelector+ clearCustomSelector,+ setDisabledSelector} from './selectors';/*** Request palette using core request utility@@ -128,7 +130,7 @@ export function clearCustoms() {const groupName = compare.activeString;const activePalettes = palettes[groupName];const props = { squash: undefined, min: undefined, max: undefined };- lodashForOwn(activePalettes, function(value, key) {+ lodashForOwn(activePalettes, function (value, key) {activePalettes[key].maps.forEach((colormap, index) => {if (colormap.custom) {dispatch(clearCustomPalette(key, index, groupName));@@ -153,5 +155,22 @@ export function loadedCustomPalettes(customs) {}// TODOexport function setToggledClassification(layerId, classIndex, index, groupName) {--}\ No newline at end of file+ return (dispatch, getState) => {+ const state = getState();+ const newActivePalettesObj = setDisabledSelector(+ layerId,+ classIndex,+ index,+ state.palettes[groupName],+ state+ );+ dispatch({+ type: SET_DISABLED_CLASSIFICATION,+ groupName: groupName,+ activeString: groupName,+ layerId,+ palettes: newActivePalettesObj,+ props: { disabled: classIndex }+ });+ };+};\ No newline at end of filediff --git a/web/js/modules/palettes/constants.js b/web/js/modules/palettes/constants.jsindex 69866e483..bbe863216 100644--- a/web/js/modules/palettes/constants.js+++ b/web/js/modules/palettes/constants.js@@ -2,7 +2,7 @@ export const REQUEST_PALETTE = 'PALETTES/REQUEST_PALETTE';export const REQUEST_PALETTE_START = 'PALETTES/REQUEST_PALETTE_START';export const REQUEST_PALETTE_SUCCESS = 'PALETTES/REQUEST_PALETTE_SUCCESS';export const REQUEST_PALETTE_FAILURE = 'PALETTES/REQUEST_PALETTE_FAILURE';-+export const SET_DISABLED_CLASSIFICATION = 'PALETTES/SET_DISABLED_CLASSIFICATION';export const PALETTE_CHANGE = 'PALETTES/CHANGE_OF_ACTIVE_PALETTE';export const SET_THRESHOLD_RANGE_AND_SQUASH = 'PALETTES/SET_THRESHOLD_RANGE_AND_SQUASH';export const CLEAR_CUSTOM = 'PALETTES/CLEAR_CUSTOM';diff --git a/web/js/modules/palettes/reducers.js b/web/js/modules/palettes/reducers.jsindex fdf77d424..30391fa17 100644--- a/web/js/modules/palettes/reducers.js+++ b/web/js/modules/palettes/reducers.js@@ -11,7 +11,8 @@ import {SET_THRESHOLD_RANGE_AND_SQUASH,LOADED_CUSTOM_PALETTES,BULK_PALETTE_RENDERING_SUCCESS,- CLEAR_CUSTOM+ CLEAR_CUSTOM,+ SET_DISABLED_CLASSIFICATION} from './constants';import { INIT_SECOND_LAYER_GROUP } from '../layers/constants';import update from 'immutability-helper';@@ -63,6 +64,7 @@ export function paletteReducer(state = defaultPaletteState, action) {});case SET_THRESHOLD_RANGE_AND_SQUASH:case SET_CUSTOM:+ case SET_DISABLED_CLASSIFICATION:case CLEAR_CUSTOM:return lodashAssign({}, state, {[groupName]: action.palettes || {}diff --git a/web/js/modules/palettes/selectors.js b/web/js/modules/palettes/selectors.jsindex 7e11f3830..c8d92bbd2 100644--- a/web/js/modules/palettes/selectors.js+++ b/web/js/modules/palettes/selectors.js@@ -109,10 +109,10 @@ export function getCustomPalette(paletteId, customsPaletteConfig) {}return palette;}-var useLookup = function(layerId, palettesObj, state) {+var useLookup = function (layerId, palettesObj, state) {var use = false;var active = palettesObj[layerId].maps;- lodashEach(active, function(palette, index) {+ lodashEach(active, function (palette, index) {if (palette.custom) {use = true;return false;@@ -129,6 +129,8 @@ var useLookup = function(layerId, palettesObj, state) {use = true;return false;}+ } else if (palette.legend.colors.length > 1) {+ use = true;}});return use;@@ -138,15 +140,16 @@ export function getLookup(layerId, groupstr, state) {groupstr = groupstr || state.compare.activeString;return state.palettes[groupstr][layerId].lookup;}-var updateLookup = function(layerId, palettesObj, state) {+var updateLookup = function (layerId, palettesObj, state) {let newPalettes = palettesObj;if (!useLookup(layerId, newPalettes, state)) {delete newPalettes[layerId];return newPalettes;}+var lookup = {};var active = newPalettes[layerId].maps;- lodashEach(active, function(palette, index) {+ lodashEach(active, function (palette, index) {var oldLegend = palette.legend;var entries = palette.entries;const refs = oldLegend.refs;@@ -172,9 +175,13 @@ var updateLookup = function(layerId, palettesObj, state) {var sourceCount = source.length;var targetCount = target.length;var appliedLegends = [];- lodashEach(source, function(color, index) {+ var disabled = palette.disabled || [];+ lodashEach(source, function (color, index) {var targetColor;- if (index < min || index > max) {+ if (index < min || index > max || disabled.includes(index)) {+ if (disabled.includes(index)) {+ console.log(disabled)+ }targetColor = '00000000';} else {var sourcePercent, targetIndex;@@ -230,7 +237,7 @@ export function findIndex(layerId, type, value, index, groupStr, state) {index = index || 0;var values = getPalette(layerId, index, groupStr, state).entries.values;var result;- lodashEach(values, function(check, index) {+ lodashEach(values, function (check, index) {var min = getMinValue(check);var max = getMaxValue(check);if (type === 'min' && value === min) {@@ -284,6 +291,31 @@ export function isActive(layerId, group, state) {group = group || state.compare.activeString;return state.palettes[group][layerId];}+export function setDisabledSelector(+ layerId,+ classIndex,+ index,+ palettes,+ state+) {+ let newPalettes = prepare(layerId, palettes, state);+ let legend = getPalette(layerId, index, undefined, state);+ let oldDisabled = legend.disabled || [];+ const indexOf = oldDisabled.indexOf(classIndex);+ indexOf !== -1 ? oldDisabled.splice(indexOf, 1) : oldDisabled.push(classIndex);+ newPalettes = update(newPalettes, {+ [layerId]: {+ maps: {+ [index]: {+ $merge: {+ disabled: oldDisabled+ }+ }+ }+ }+ });+ return updateLookup(layerId, newPalettes, state);+}export function setRange(layerId, props, index, palettes, state) {let min = props.min;let max = props.max;@@ -335,12 +367,12 @@ export function clearCustomSelector(layerId, index, palettes, state) {}); // remove custom keyreturn updateLookup(layerId, newPalettes, state);}-var prepare = function(layerId, palettesObj, state) {+var prepare = function (layerId, palettesObj, state) {var newPalettes = lodashCloneDeep(palettesObj);if (!newPalettes[layerId]) newPalettes[layerId] = {};var active = newPalettes[layerId];active.maps = active.maps || [];- lodashEach(getRenderedPalette(layerId, undefined, state).maps, function(+ lodashEach(getRenderedPalette(layerId, undefined, state).maps, function (palette,index) {