Interactive interface for browsing global, full-resolution satellite imagery
Add classification toggle to Permalink #2306
Benjamin King25311ad07f2b
diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.jsindex fe3af29da..9ba37f152 100644--- a/web/js/components/sidebar/paletteLegend.js+++ b/web/js/components/sidebar/paletteLegend.js@@ -398,7 +398,6 @@ 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/layers/reducers.js b/web/js/modules/layers/reducers.jsindex 7985d63fe..62280de7c 100644--- a/web/js/modules/layers/reducers.js+++ b/web/js/modules/layers/reducers.js@@ -12,7 +12,8 @@ import {import {SET_CUSTOM as SET_CUSTOM_PALETTE,CLEAR_CUSTOM as CLEAR_CUSTOM_PALETTE,- SET_THRESHOLD_RANGE_AND_SQUASH+ SET_THRESHOLD_RANGE_AND_SQUASH,+ SET_DISABLED_CLASSIFICATION} from '../palettes/constants';import {CLEAR_VECTORSTYLE,@@ -67,7 +68,8 @@ export function layerReducer(state = initialState, action) {[action.index]: { visible: { $set: action.visible } }}});- case SET_THRESHOLD_RANGE_AND_SQUASH: {+ case SET_THRESHOLD_RANGE_AND_SQUASH:+ case SET_DISABLED_CLASSIFICATION: {const layerIndex = lodashFindIndex(state[layerGroupStr], {id: action.layerId});diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.jsindex 59edb94a9..61b4f281c 100644--- a/web/js/modules/layers/selectors.js+++ b/web/js/modules/layers/selectors.js@@ -117,6 +117,7 @@ export function addLayer(id, spec, layers, layerConfig, overlayLength) {def.custom = spec.custom || undefined;def.max = spec.max || undefined;def.squash = spec.squash || undefined;+ def.disabled = spec.disabled || undefined;if (!lodashIsUndefined(spec.visible)) {def.visible = spec.visible;diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex a50e84652..31ab236e5 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -228,8 +228,7 @@ export function serializeLayers(currentLayers, state, groupName) {value: def.opacity});}-- if (def.palette && (def.custom || def.min || def.max || def.squash)) {+ if (def.palette && (def.custom || def.min || def.max || def.squash || def.disabled)) {// If layer has palette and palette attributesconst paletteAttributeArray = getPaletteAttributeArray(def.id,@@ -461,7 +460,7 @@ const createLayerArrayFromState = function(state, config) {lodashEachRight(state, function(layerDef) {let hidden = false;let opacity = 1.0;- let max, min, squash, custom;+ let max, min, squash, custom, disabled;if (!config.layers[layerDef.id]) {console.warn('No such layer: ' + layerDef.id);return;@@ -474,6 +473,10 @@ const createLayerArrayFromState = function(state, config) {opacity = util.clamp(parseFloat(attr.value), 0, 1);if (isNaN(opacity)) opacity = 0; // "opacity=0.0" is opacity in URL, resulting in NaN}+ if (attr.id === 'disabled') {+ const values = util.toArray(attr.value.split(';'));+ disabled = values;+ }if (attr.id === 'max' && typeof attr.value === 'string') {const maxArray = [];const values = util.toArray(attr.value.split(';'));@@ -539,7 +542,8 @@ const createLayerArrayFromState = function(state, config) {...(isArray(custom) && { custom }),...(isArray(min) && { min }),...(isArray(squash) && { squash }),- ...(isArray(max) && { max })+ ...(isArray(max) && { max }),+ ...(isArray(disabled) && { disabled })},layerArray,config.layersdiff --git a/web/js/modules/palettes/actions.js b/web/js/modules/palettes/actions.jsindex e1254b6f9..927ba2a70 100644--- a/web/js/modules/palettes/actions.js+++ b/web/js/modules/palettes/actions.js@@ -164,13 +164,19 @@ export function setToggledClassification(layerId, classIndex, index, groupName)state.palettes[groupName],state);+ let hasDisabled = false;+ newActivePalettesObj[layerId].maps.forEach(colorMap => {+ if (colorMap.disabled && colorMap.disabled.length) {+ hasDisabled = true;+ }+ });dispatch({type: SET_DISABLED_CLASSIFICATION,groupName: groupName,activeString: groupName,layerId,palettes: newActivePalettesObj,- props: { disabled: classIndex }+ props: { disabled: hasDisabled }});};};diff --git a/web/js/modules/palettes/constants.js b/web/js/modules/palettes/constants.jsindex bbe863216..e6b857aca 100644--- a/web/js/modules/palettes/constants.js+++ b/web/js/modules/palettes/constants.js@@ -16,6 +16,7 @@ export const PALETTE_STRINGS_PERMALINK_ARRAY = ['palette','squash','min',- 'max'+ 'max',+ 'disabled'];-export const CUSTOM_PALETTE_TYPE_ARRAY = ['custom', 'squash', 'min', 'max'];+export const CUSTOM_PALETTE_TYPE_ARRAY = ['custom', 'squash', 'min', 'max', 'disabled'];diff --git a/web/js/modules/palettes/selectors.js b/web/js/modules/palettes/selectors.jsindex 2d2fbf0bd..7936ec917 100644--- a/web/js/modules/palettes/selectors.js+++ b/web/js/modules/palettes/selectors.js@@ -342,6 +342,29 @@ export function isActive(layerId, group, state) {group = group || state.compare.activeString;return state.palettes[group][layerId];}+export function initDisabledSelector(+ layerId,+ disabledStr,+ index,+ palettes,+ state+) {+ const disabled = disabledStr.split('-');+ for (var i = 0; i < disabled.length; i++) { disabled[i] = +disabled[i]; }+ let newPalettes = prepare(layerId, palettes, state);+ newPalettes = update(newPalettes, {+ [layerId]: {+ maps: {+ [index]: {+ $merge: {+ disabled+ }+ }+ }+ }+ });+ return toggleLookup(layerId, newPalettes, state);+}export function setDisabledSelector(layerId,classIndex,diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.jsindex bc88d1868..07ff9dbb5 100644--- a/web/js/modules/palettes/util.js+++ b/web/js/modules/palettes/util.js@@ -13,7 +13,8 @@ import {setCustomSelector,getCount,setRange as setRangeSelector,- findIndex as findPaletteExtremeIndex+ findIndex as findPaletteExtremeIndex,+ initDisabledSelector} from './selectors';import util from '../../util/util';import Promise from 'bluebird';@@ -237,12 +238,15 @@ export function getPaletteAttributeArray(layerId, palettes, state) {let minObj = lodashAssign({}, { key: 'min', array: [] }, DEFAULT_OBJ);let maxObj = lodashAssign({}, { key: 'max', array: [] }, DEFAULT_OBJ);let squashObj = lodashAssign({}, { key: 'squash', array: [] }, DEFAULT_OBJ);+ let disabledObj = lodashAssign({}, { key: 'disabled', array: [] }, DEFAULT_OBJ);const attrArray = [];for (var i = 0; i < count; i++) {if (!palettes[layerId].maps[i]) {console.warn('NO PALETTE');}+const paletteDef = palettes[layerId].maps[i];+const entryLength =lodashSize(lodashGet(paletteDef, 'entries.values')) ||lodashSize(lodashGet(paletteDef, 'entries.colors'));@@ -252,6 +256,10 @@ export function getPaletteAttributeArray(layerId, palettes, state) {const minValue = paletteDef.min? lodashSplit(paletteDef.entries.values[paletteDef.min || 0], ',', 1): undefined;+ const disabledValue = paletteDef.disabled && paletteDef.disabled.length+ ? paletteDef.disabled.join('-')+ : undefined;+palObj = createPaletteAttributeObject(paletteDef,paletteDef.custom,@@ -277,9 +285,15 @@ export function getPaletteAttributeArray(layerId, palettes, state) {squashObj,count);+ disabledObj = createPaletteAttributeObject(+ paletteDef,+ disabledValue,+ disabledObj,+ count+ );}- [palObj, minObj, maxObj, squashObj].forEach(obj => {+ [palObj, minObj, maxObj, squashObj, disabledObj].forEach(obj => {if (obj.isActive) {attrArray.push({id: obj.key === 'custom' ? 'palette' : obj.key,@@ -287,7 +301,6 @@ export function getPaletteAttributeArray(layerId, palettes, state) {});}});-return attrArray;} catch (e) {console.warn('Error parsing palette: ' + e);@@ -321,6 +334,7 @@ const createPaletteAttributeObject = function(def, value, attrObj, count) {*/export function loadPalettes(permlinkState, state) {var stateArray = [{ stateStr: 'l', groupStr: 'active' }];+ const palettes = state.palettes;if (!isSupported()) {return state;}@@ -395,7 +409,24 @@ export function loadPalettes(permlinkState, state) {if (layerDef.squash) {squash = layerDef.squash;}-+ if (layerDef.disabled) {+ lodashEach(layerDef.disabled, function(value, index) {+ try {+ const newPalettes = initDisabledSelector(+ layerId,+ value,+ index,+ palettes[stateObj.groupStr],+ state+ );+ state = update(state, {+ palettes: { [stateObj.groupStr]: { $set: newPalettes } }+ });+ } catch (error) {+ console.warn(' Invalid palette: ' + value);+ }+ });+ }if (min.length > 0 || max.length > 0) {count = getCount(layerId, state);for (var i = 0; i < count; i++) {