Interactive interface for browsing global, full-resolution satellite imagery
WV-3872 (#6337)
Tom Cariello45ee771d82a3
diff --git a/web/js/components/sidebar/paletteLegend.js b/web/js/components/sidebar/paletteLegend.jsindex f848c51df..8fdfa7fd1 100644--- a/web/js/components/sidebar/paletteLegend.js+++ b/web/js/components/sidebar/paletteLegend.js@@ -195,10 +195,18 @@ class PaletteLegend extends React.Component {}/**- * Find wanted legend object from Hex- * @param {Object} legend- * @param {String} hex- * @param {Number} acceptableDifference+ * Finds the legend object that corresponds to a given hex color.+ *+ * @param {Object} legend - The legend object containing colors and tooltips.+ * @param {string[]} legend.colors - Array of hex color strings in the legend.+ * @param {string[]} legend.tooltips - Array of tooltip strings corresponding to colors.+ * @param {string} [legend.units] - Optional units for the legend values.+ * @param {string} hex - The hex color to match against the legend.+ * @param {number} acceptableDifference - The maximum allowed difference between colors.+ * Lower values require closer color matches.+ *+ * @returns {Object|null} The matched legend object or null if no match is found.+ **/getLegendObject(legend, hex, acceptableDifference) {const { globalTemperatureUnit } = this.props;@@ -249,7 +257,9 @@ class PaletteLegend extends React.Component {const toolTipLength = legend.tooltips.length;// eslint-disable-next-line react/destructuring-assignmentif (isRunningData && colorHex && this.state.width > 0) {- legendObj = this.getLegendObject(legend, colorHex, 3); // {label,len,index}+ const isContinuousVectorLayer = layer.colormapType === 'continuous' && layer.type === 'vector';+ const acceptableDifference = isContinuousVectorLayer ? 1 : 3;+ legendObj = this.getLegendObject(legend, colorHex, acceptableDifference); // {label,len,index}if (legendObj) {percent = this.getPercent(legendObj.len, legendObj.index);textWidth = util.getTextWidth(legendObj.label, '10px Open Sans');diff --git a/web/js/map/runningdata.js b/web/js/map/runningdata.jsindex 417665a84..fc4fed7f1 100644--- a/web/js/map/runningdata.js+++ b/web/js/map/runningdata.js@@ -58,17 +58,17 @@ export default function MapRunningData(compareUi, store) {// Running data for vector layersmap.forEachFeatureAtPixel(pixel, (feature, layer) => {if (shouldNotProcessVectorLayer(layer)) return;-const { id, palette } = layer.wv.def;+ const isContinuousVectorLayer = layer.wv.def.colormapType === 'continuous' && layer.wv.def.type === 'vector';const identifier = palette.styleProperty;const paletteLegends = getPalette(id, undefined, undefined, state);const { legend } = paletteLegends;let color;- if (!identifier && legend.colors.length > 1) return;+ if (!isContinuousVectorLayer && !identifier && legend.colors.length > 1) return;+ const featureProps = feature.getProperties();if (identifier) {- const properties = feature.getProperties();- const value = properties[identifier] || palette.unclassified;+ const value = featureProps[identifier] || palette.unclassified;if (!value) return;const tooltips = legend.tooltips.map((c) => c.toLowerCase().replace(/\s/g, ''));if (id.includes('AERONET')) {@@ -88,6 +88,31 @@ export default function MapRunningData(compareUi, store) {const colorIndex = tooltips.indexOf(value.toLowerCase().replace(/\s/g, ''));color = legend.colors[colorIndex];}+ } else if (isContinuousVectorLayer) {+ const measurementValue = featureProps.Value;+ const numericValue = parseFloat(measurementValue);+ if (Number.isNaN(numericValue)) return;++ const colorIndex = legend.tooltips.findIndex((tooltip) => {+ if (tooltip.includes('≥') || tooltip.includes('>')) {+ const min = parseFloat(tooltip.replace(/[≥>]/g, '').trim());+ return numericValue >= min;+ }++ if (tooltip.includes('≤') || tooltip.includes('<')) {+ const max = parseFloat(tooltip.replace(/[≤<]/g, '').trim());+ return numericValue <= max;+ }++ if (tooltip.includes('-')) {+ const [min, max] = tooltip.split('-').map((s) => parseFloat(s.trim()));+ return numericValue >= min && numericValue < max;+ }++ return false;+ });++ color = legend.colors[colorIndex];} else if (legend.colors.length === 1) {[color] = legend.colors;}