Interactive interface for browsing global, full-resolution satellite imagery
Classifications toggle [wip] #2306
Benjamin King749782c60a21
diff --git a/web/css/palettes.css b/web/css/palettes.cssindex a70773e20..e2cea122b 100644--- a/web/css/palettes.css+++ b/web/css/palettes.css@@ -194,6 +194,7 @@display: inline-block;border: 1px solid #000;margin: 0 2px 4px;+ position: relative;}.wv-running .wv-palettes-class {opacity: 0.25;@@ -245,3 +246,11 @@width: 100%;text-align: center;}+.disabled-classification:before {+ border-top: 1px solid rgb(252, 3, 3);+ content: '';+ position: absolute;+ right: 0; left: -50%;+ transform: rotate(-45deg);+ transform-origin: 100% 0;+}diff --git a/web/css/util.css b/web/css/util.cssindex bdeed2634..5b2bffd35 100644--- a/web/css/util.css+++ b/web/css/util.css@@ -209,9 +209,4 @@ 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 0;-}+}\ 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 43dd7147c..545e92ebb 100644--- a/web/js/components/layer/settings/classification-toggle.js+++ b/web/js/components/layer/settings/classification-toggle.js@@ -13,9 +13,8 @@ class ClassificationToggle extends React.Component {}render() {- const { legend, toggle } = this.props;+ const { legend, toggle, palette } = this.props;const tooltips = legend.tooltips;-return (<div className="layer-classification-toggle settings-component"><h2 className="wv-header">Category Enable/Disable</h2>@@ -23,7 +22,7 @@ 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);+ const inActive = palette.disabled && palette.disabled.includes(index);return (<Switchid={id}diff --git a/web/js/components/layer/settings/settings.js b/web/js/components/layer/settings/settings.jsindex a2f356c25..9df15a290 100644--- a/web/js/components/layer/settings/settings.js+++ b/web/js/components/layer/settings/settings.js@@ -121,7 +121,7 @@ class LayerSettings extends React.Component {) : null}{(legend.type === 'classification' && legend.colors.length > 1) ? (- <ClassificationToggle toggle={(classIndex) => toggleClassification(layer.id, classIndex, i, groupName)} legend={legend} />+ <ClassificationToggle palette={palette} toggle={(classIndex) => toggleClassification(layer.id, classIndex, i, groupName)} legend={legend} />) : null}<Palette@@ -183,7 +183,7 @@ class LayerSettings extends React.Component {if (len > 1) {return this.renderMultiColormapCustoms(paletteLegends);} else if (legend.type === 'classification' && legend.colors.length > 1) {- return (<ClassificationToggle toggle={(classIndex) => toggleClassification(layer.id, classIndex, 0, groupName)} legend={legend} />);+ return (<ClassificationToggle palette={palette} toggle={(classIndex) => toggleClassification(layer.id, classIndex, 0, groupName)} legend={legend} />);}return (<React.Fragment>diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.jsindex cbd053485..315137650 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"@@ -319,7 +319,7 @@ class PaletteLegend extends React.Component {*/renderClasses(legend, legendIndex) {const { isRunningData, colorHex, scrollContainerEl } = this.state;- const { layer, parentLayer, layerGroupName } = this.props;+ const { layer, parentLayer, layerGroupName, getPalette } = this.props;const activeKeyObj = isRunningData && colorHex && this.getLegendObject(legend, colorHex, 5);const legendClass = activeKeyObj? 'wv-running wv-palettes-legend wv-palettes-classes'@@ -329,7 +329,7 @@ class PaletteLegend extends React.Component {const trackLabel = layer.track && legendTooltip? `${legendTooltip} - ${getOrbitTrackTitle(layer)}`: getOrbitTrackTitle(layer);-+ const palette = getPalette(layer.id, legendIndex);return (<VisibilitySensorkey={legend.id + '-' + legendIndex + 'vis-sensor'}@@ -345,16 +345,17 @@ class PaletteLegend extends React.Component {const parentLayerId = isSubLayer ? parentLayer.id : '';const keyId = layer.id + '-' + legend.id + '-color-' + keyIndex + parentLayerId + layerGroupName;const keyLabel = activeKeyObj ? activeKeyObj.label : '';++ const inActive = palette.disabled && palette.disabled.includes(keyIndex);const tooltipText = singleKey? layer.track ? trackLabel : legendTooltip: keyLabel;-return (<React.Fragment key={keyId}><spanid={keyId}- className={color === '00000000' ? palletteClass + ' checker-board-pattern' : palletteClass}- style={color === '00000000' ? {} : { backgroundColor: util.hexToRGBA(color) }}+ className={inActive ? palletteClass + ' disabled-classification' : palletteClass}+ style={{ backgroundColor: util.hexToRGBA(color) }}onMouseMove={this.onMove.bind(this, color)}onMouseEnter={this.onMouseEnter.bind(this)}onMouseLeave={this.hideValue.bind(this)}@@ -397,6 +398,7 @@ class PaletteLegend extends React.Component {this['canvas_' + index] = React.createRef();return this.renderScale(colorMap, index, paletteLegends.length > 1);} else if (colorMap.type === 'classification') {+ console.log(paletteLegends)return this.renderClasses(colorMap, index);}});diff --git a/web/js/modules/palettes/selectors.js b/web/js/modules/palettes/selectors.jsindex 4efd08ae5..c2e5b639a 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;@@ -140,7 +140,7 @@ 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];@@ -149,7 +149,7 @@ var updateLookup = function(layerId, palettesObj, state) {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;@@ -176,7 +176,7 @@ var updateLookup = function(layerId, palettesObj, state) {var targetCount = target.length;var appliedLegends = [];var disabled = palette.disabled || [];- lodashEach(source, function(color, index) {+ lodashEach(source, function (color, index) {var targetColor;if (index < min || index > max || disabled.includes(index)) {targetColor = '00000000';@@ -229,12 +229,66 @@ var updateLookup = function(layerId, palettesObj, state) {});return update(newPalettes, { [layerId]: { lookup: { $set: lookup } } });};+var toggleLookup = 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) {+ var entries = palette.entries;+ const refs = palette.legend.refs;+ var source = entries.colors;+ var target = palette.custom+ ? getCustomPalette(palette.custom, state.palettes.custom).colors+ : source;++ var sourceCount = source.length;+ var targetCount = target.length;+ var appliedLegends = [];+ var disabled = palette.disabled || [];+ lodashEach(source, function (color, index) {+ var targetColor;+ if (disabled.includes(index)) {+ targetColor = '00000000';+ } else {+ var sourcePercent, targetIndex;+ sourcePercent = index / sourceCount;+ targetIndex = Math.floor(sourcePercent * targetCount);+ targetColor = target[targetIndex];+ }+ const colormapRef = entries.refs[index];+ const refIndex = refs.indexOf(colormapRef);+ if (~refIndex && !appliedLegends.includes(colormapRef)) {+ appliedLegends.push(colormapRef);+ }+ var lookupSource =+ lodashParseInt(color.substring(0, 2), 16) ++ ',' ++ lodashParseInt(color.substring(2, 4), 16) ++ ',' ++ lodashParseInt(color.substring(4, 6), 16) ++ ',' ++ lodashParseInt(color.substring(6, 8), 16);+ var lookupTarget = {+ r: lodashParseInt(targetColor.substring(0, 2), 16),+ g: lodashParseInt(targetColor.substring(2, 4), 16),+ b: lodashParseInt(targetColor.substring(4, 6), 16),+ a: lodashParseInt(targetColor.substring(6, 8), 16)+ };+ lookup[lookupSource] = lookupTarget;+ });+ });+ return update(newPalettes, { [layerId]: { lookup: { $set: lookup } } });+};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) {@@ -311,7 +365,7 @@ export function setDisabledSelector(}}});- return updateLookup(layerId, newPalettes, state);+ return toggleLookup(layerId, newPalettes, state);}export function setRange(layerId, props, index, palettes, state) {let min = props.min;@@ -364,12 +418,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) {