Interactive interface for browsing global, full-resolution satellite imagery
Display legendEntries as legend instead of colormaps #2216
Benjamin King9090304459ee
diff --git a/tasks/python3/processColormap.py b/tasks/python3/processColormap.pyindex efdb4ab42..60333d68a 100755--- a/tasks/python3/processColormap.py+++ b/tasks/python3/processColormap.py@@ -44,76 +44,6 @@ def match_legend(entry, legends):except ValueError as e:raise ValueError("Invalid reference: %s" % entry["@ref"])-# function returns a max or-# min value from a list-def get_extreme(extreme_list, extreme):- if(extreme == "max"):- if "+INF" in extreme_list:- return 'infinity'- else:- return max(extreme_list)- else:- if "-INF" in extreme_list:- return "neg-infinity"- else:- return min(extreme_list)--# Adds tooltip string to selected-# indexes that need to be replace.-def apply_tooltip(tooltip, tooltip_list, index_list):- for index in index_list:- tooltip_list[index] = tooltip- return tooltip_list--# to combines data values of corresponding-# colors-def replace_duplicates(duplicates, tooltip_list, entries):- dup_color_list = list(set(duplicates)) #removes array duplicates- for n, color in enumerate(dup_color_list): # loops through duplicate colors- min_list = []- max_list = []- index_list = []-- for index, entry in enumerate(entries):- if(color == entry["@rgb"]):- # get min- value = entry['@value']- value = value.split(',')- if(len(value) > 1):- value[0] = value[0].replace("[", "")- min_list += [value[0]] # adds value to min array- # get max- value[1] = value[1].replace(")", "")- max_list += [value[1]] # adds value to max array- # add index- else:- min_list += [value[0]] # adds value to min array- max_list += [value[0]] # adds value to max array- index_list += [index]-- # get max and min values- max_value = get_extreme(max_list, "max")- min_value = get_extreme(min_list, "min")- sep = ' - '- # handle infinity values- if(max_value == "infinity" or min_value == "neg-infinity"):- if(min_value == "neg-infinity"):- tooltip = '< ' + max_value- else:- tooltip = '>= ' + min_value- # zero range delta- elif min_value == max_value:- tooltip = min_value- # two different none-infinity values- # in range- else:- tooltip = min_value + sep + max_value-- tooltip_list = apply_tooltip(tooltip, tooltip_list, index_list)--- return tooltip_list-def process_entries(colormap):entries = to_list(colormap["Entries"]["ColorMapEntry"])@@ -134,28 +64,24 @@ def process_entries(colormap):values = []ticks = []tooltips = []- matches = []-+ legend_colors = []+ refs_list = []+ ref_skip_list = []color_format = "{0:02x}{1:02x}{2:02x}{3:02x}"for index, entry in enumerate(entries):legend = match_legend(entry, legends)if (legend == "false"):+ ref_skip_list += [entry['@ref']]continuer,g,b = entry["@rgb"].split(",")a = 0 if entry.get("@transparent", "false") == "true" else 255if a == 0:+ ref_skip_list += [entry['@ref']]continue+ if "@ref" not in entry:+ raise KeyError("No ref in legend")+ refs_list += [entry['@ref']]colors += [color_format.format(int(r), int(g), int(b), a)]- if "@tooltip" not in legend:- raise KeyError("No tooltips in legend")- tooltip = legend["@tooltip"]- if (index > 0):- if (entry["@rgb"] == entries[index-1]["@rgb"]):- if (map_type == "continuous") or (map_type == "discrete"):- matches += [entry["@rgb"]]- tooltips += [tooltip]- if "@showTick" in legend:- ticks.append(index)if (map_type == "continuous") or (map_type == "discrete"):items = re.sub(r"[\(\)\[\]]", "", entry["@value"]).split(",")try:@@ -170,20 +96,36 @@ def process_entries(colormap):values += [new_items]except ValueError as e:raise ValueError("Invalid value: %s" % entry["@value"])- if (len(matches) > 0 and len(tooltips) > 0):- tooltips = replace_duplicates(matches, tooltips, entries)+ skip_index = 0+ id_list = []+ for index, entry in enumerate(legends):+ if entry['@id'] in ref_skip_list:+ skip_index = skip_index + 1+ continue+ r,g,b = entry["@rgb"].split(",")+ legend_colors += [color_format.format(int(r), int(g), int(b), 255)]+ if "@tooltip" not in entry:+ raise KeyError("No tooltips in legend")+ tooltips += [entry["@tooltip"]]+ if "@id" not in entry:+ raise KeyError("No id in legend")+ id_list += [entry['@id']]+ if "@showTick" in entry:+ ticks += [index - skip_index]result = {"type": map_type,"entries": {"type": map_type,"colors": colors,+ "refs": refs_list},"legend": {- "tooltips": tooltips,- "colors": colors,+ "colors": legend_colors,"type": map_type,- "ticks": ticks+ "tooltips": tooltips,+ "ticks": ticks,+ "refs": id_list}}if (map_type == "continuous") or (map_type == "discrete"):diff --git a/web/js/components/layer/settings/palette-threshold.js b/web/js/components/layer/settings/palette-threshold.jsindex 0141ed51d..f5b6ecdf2 100644--- a/web/js/components/layer/settings/palette-threshold.js+++ b/web/js/components/layer/settings/palette-threshold.js@@ -2,15 +2,16 @@ import React from 'react';import PropTypes from 'prop-types';import lodashDebounce from 'lodash/debounce';import { Range as RangeInput } from 'rc-slider';-+import { getFirstIndexFromRef } from '../../../modules/palettes/util'import { Checkbox } from '../../util/checkbox';class ThresholdSelect extends React.Component {constructor(props) {super(props);+ const { start, end, palette, legend } = props;this.state = {- start: props.start,- end: props.end,+ start: start ? getFirstIndexFromRef(palette.entries.refs[start], legend.refs) : start,+ end: end ? getFirstIndexFromRef(palette.entries.refs[end], legend.refs) : start,squashed: props.squashed,activeDragger: 'start'};@@ -22,13 +23,16 @@ class ThresholdSelect extends React.Component {* @param {Boolean} boo*/updateSquash(boo) {- const { setRange, layerId, index, groupName } = this.props;+ const { setRange, layerId, index, groupName, palette, legend } = this.props;const { start, end, squashed } = this.state;const isSquashed = !squashed;+ const startIndex = legend.refs[start];+ const endIndex = legend.refs[end];+setRange(layerId,- parseFloat(start),- parseFloat(end),+ parseFloat(getFirstIndexFromRef(startIndex, palette.entries.refs)),+ parseFloat(getFirstIndexFromRef(endIndex, palette.entries.refs)),isSquashed,index,groupName@@ -41,11 +45,13 @@ class ThresholdSelect extends React.Component {* @param {Array} thresholdArray | Array of start/end indexs for colormap*/updateThreshold(thresholdArray) {- const { layerId, index, groupName } = this.props;+ const { layerId, index, groupName, palette, legend } = this.props;const { start, end } = this.state;-const newStart = Math.ceil(Number(thresholdArray[0]));const newEnd = Math.ceil(Number(thresholdArray[1]));+ const startRef = legend.refs[newStart];+ const endRef = legend.refs[newEnd];+if (newStart !== start && newEnd !== end) {this.setState({start: newStart,@@ -63,10 +69,11 @@ class ThresholdSelect extends React.Component {return;}// Update local state on every range-selector change but debounce threshold model update+this.debounceSetRange(layerId,- parseFloat(newStart),- parseFloat(newEnd),+ parseFloat(getFirstIndexFromRef(startRef, palette.entries.refs)),+ parseFloat(getFirstIndexFromRef(endRef, palette.entries.refs)),this.state.squashed,index,groupNamediff --git a/web/js/components/layer/settings/settings.js b/web/js/components/layer/settings/settings.jsindex 9a4b21def..2549e50c6 100644--- a/web/js/components/layer/settings/settings.js+++ b/web/js/components/layer/settings/settings.js@@ -110,10 +110,11 @@ class LayerSettings extends React.Component {layerId={layer.id}squashed={!!palette.squash}index={i}+ palette={palette}/>) : (- ''- )}+ ''+ )}<PalettesetCustomPalette={setCustomPalette}groupName={groupName}@@ -189,6 +190,7 @@ class LayerSettings extends React.Component {squashed={!!palette.squash}groupName={groupName}index={0}+ palette={palette}/>}<Palettediff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.jsindex 184b5a531..a5cd8b798 100644--- a/web/js/components/sidebar/paletteLegend.js+++ b/web/js/components/sidebar/paletteLegend.js@@ -1,7 +1,7 @@import React from 'react';import PropTypes from 'prop-types';import util from '../../util/util';-import { drawSidebarPaletteOnCanvas, drawTicksOnCanvas } from '../../modules/palettes/util';+import { drawSidebarPaletteOnCanvas, drawTicksOnCanvas, getFirstIndexFromRef } from '../../modules/palettes/util';import lodashIsNumber from 'lodash/isNumber';class PaletteLegend extends React.Component {@@ -237,8 +237,8 @@ class PaletteLegend extends React.Component {}var min = legend.minLabel || legend.tooltips[0];var max = legend.maxLabel || legend.tooltips[toolTipLength];- min = palette.min ? legend.tooltips[palette.min] : min;- max = palette.max ? legend.tooltips[palette.max] : max;+ min = palette.min ? legend.tooltips[getFirstIndexFromRef(palette.entries.refs[palette.min], legend.refs)] : min;+ max = palette.max ? legend.tooltips[getFirstIndexFromRef(palette.entries.refs[palette.max], legend.refs)] : max;min = legend.units ? min + ' ' + legend.units : min;max = legend.units ? max + ' ' + legend.units : max;@@ -253,8 +253,8 @@ class PaletteLegend extends React.Component {{isMoreThanOneColorBar ? (<div className="wv-palettes-title">{legend.title}</div>) : (- ''- )}+ ''+ )}<div className="colorbar-case"><canvasclassName="wv-palettes-colorbar"@@ -375,8 +375,8 @@ class PaletteLegend extends React.Component {)}</div>) : (- ''- )}+ ''+ )}</React.Fragment>);})}diff --git a/web/js/fixtures.js b/web/js/fixtures.jsindex e2ccf7a4d..cbbe57e15 100644--- a/web/js/fixtures.js+++ b/web/js/fixtures.js@@ -14,7 +14,7 @@ var fixtures = {light_blue: 'f0f0ffff',dark_blue: '000040'};-fixtures.getState = function() {+fixtures.getState = function () {return {compare: initialCompareState,config: fixtures.config(),@@ -32,12 +32,14 @@ fixtures.getState = function() {entries: {type: 'scale',colors: [fixtures.green, fixtures.yellow, fixtures.red],- values: [0, 1, 2]+ values: [0, 1, 2],+ refs: ['0', '1', '2']},legend: {tooltips: ['0', '1', '2'],minLabel: '0',- maxLabel: '2'+ maxLabel: '2',+ refs: ['0', '1', '2']}}]@@ -49,12 +51,14 @@ fixtures.getState = function() {entries: {type: 'scale',colors: [fixtures.green, fixtures.yellow, fixtures.red],- values: [0, 1, 2]+ values: [0, 1, 2],+ refs: ['0', '1', '2']},legend: {tooltips: ['0', '1', '2'],minLabel: '0',- maxLabel: '2'+ maxLabel: '2',+ refs: ['0', '1', '2']}}]@@ -180,7 +184,7 @@ fixtures.getState = function() {};};-fixtures.config = function() {+fixtures.config = function () {return {pageLoadTime: new Date(),now: new Date(),diff --git a/web/js/modules/palettes/selectors.js b/web/js/modules/palettes/selectors.jsindex 17f9f6a77..ad2fc981f 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;@@ -138,7 +138,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];@@ -146,16 +146,18 @@ 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;var legend = {- colors: [],+ colors: oldLegend.colors,minLabel: oldLegend.minLabel,maxLabel: oldLegend.maxLabel,tooltips: oldLegend.tooltips,ticks: oldLegend.ticks,units: oldLegend.units,+ refs: refs,type: entries.type,title: entries.title,id: oldLegend.id@@ -167,10 +169,10 @@ var updateLookup = function(layerId, palettesObj, state) {var min = palette.min || 0;var max = palette.max || source.length;-var sourceCount = source.length;var targetCount = target.length;- lodashEach(source, function(color, index) {+ var appliedLegends = [];+ lodashEach(source, function (color, index) {var targetColor;if (index < min || index > max) {targetColor = '00000000';@@ -191,7 +193,13 @@ var updateLookup = function(layerId, palettesObj, state) {}targetColor = target[targetIndex];}- legend.colors.push(targetColor);+ const colormapRef = entries.refs[index];+ const refIndex = refs.indexOf(colormapRef);++ if (~refIndex && !appliedLegends.includes(colormapRef)) {+ appliedLegends.push(colormapRef);+ legend.colors[refIndex] = targetColor;+ }var lookupSource =lodashParseInt(color.substring(0, 2), 16) +',' +@@ -222,7 +230,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) {@@ -327,12 +335,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) {diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.jsindex fc81e3cfa..650843621 100644--- a/web/js/modules/palettes/util.js+++ b/web/js/modules/palettes/util.js@@ -45,7 +45,7 @@ export function getCheckerboard() {export function palettesTranslate(source, target) {var translation = [];- lodashEach(source, function(color, index) {+ lodashEach(source, function (color, index) {var sourcePercent = index / source.length;var targetIndex = Math.floor(sourcePercent * target.length);translation.push(target[targetIndex]);@@ -134,7 +134,7 @@ export function drawTicksOnCanvas(ctx, legend, width) {}export function lookup(sourcePalette, targetPalette) {var lookup = {};- lodashEach(sourcePalette.colors, function(sourceColor, index) {+ lodashEach(sourcePalette.colors, function (sourceColor, index) {var source =parseInt(sourceColor.substring(0, 2), 16) +',' +@@ -219,6 +219,9 @@ export function isSupported() {var browser = util.browser;return !(browser.ie || !browser.webWorkers || !browser.cors);}+export function getFirstIndexFromRef(ref, array) {+ return array.indexOf(ref);+}/*** Serialize palette info for layer*@@ -293,7 +296,7 @@ export function getPaletteAttributeArray(layerId, palettes, state) {return [];}}-const createPaletteAttributeObject = function(def, value, attrObj, count) {+const createPaletteAttributeObject = function (def, value, attrObj, count) {const key = attrObj.key;const attrArray = attrObj.array;let hasAtLeastOnePair = attrObj.isActive;@@ -330,7 +333,7 @@ export function loadPalettes(permlinkState, state) {];}lodashEach(stateArray, stateObj => {- lodashEach(state.layers[stateObj.groupStr], function(layerDef) {+ lodashEach(state.layers[stateObj.groupStr], function (layerDef) {if (layerDef.palette) {var layerId = layerDef.id;var min = [];@@ -338,7 +341,7 @@ export function loadPalettes(permlinkState, state) {var squash = [];var count = 0;if (layerDef.custom) {- lodashEach(layerDef.custom, function(value, index) {+ lodashEach(layerDef.custom, function (value, index) {try {const newPalettes = setCustomSelector(layerId,@@ -356,7 +359,7 @@ export function loadPalettes(permlinkState, state) {});}if (layerDef.min) {- lodashEach(layerDef.min, function(value, index) {+ lodashEach(layerDef.min, function (value, index) {try {min.push(findPaletteExtremeIndex(@@ -374,7 +377,7 @@ export function loadPalettes(permlinkState, state) {});}if (layerDef.max) {- lodashEach(layerDef.max, function(value, index) {+ lodashEach(layerDef.max, function (value, index) {try {max.push(findPaletteExtremeIndex(