Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

clean up conditional vector style rendering #2180

Benjamin Kingaf4746aaedeb
diff --git a/web/js/components/layer/settings/vector-style.js b/web/js/components/layer/settings/vector-style.js
index 371450c04..ecd0c7b89 100644
--- a/web/js/components/layer/settings/vector-style.js
+++ b/web/js/components/layer/settings/vector-style.js
@@ -34,71 +34,69 @@ class VectorStyleSelect extends React.Component {
const { activeVectorStyle } = this.state;
var description = styleLayerObject['source-description'] || styleLayerObject.id;
const isConditionalStyling = styleLayerObject.paint ? isConditional(styleLayerObject.paint['line-color'] || styleLayerObject.paint['circle-color'] || styleLayerObject.paint['fill-color']) : false;
- console.log(isConditionalStyling);
- return isConditionalStyling ? this.renderSelectorItemMulti(styleLayerObject,
+
+ return isConditionalStyling ? this.renderLegendMultiItem(styleLayerObject,
styleLayerObject.id,
- description,
- activeVectorStyle === styleLayerObject.id) :
- this.renderSelectorItemSingle(
+ description)
+ : this.renderSelectorItemSingle(
styleLayerObject,
styleLayerObject.id,
description,
activeVectorStyle === styleLayerObject.id
);
}
- renderSelectorItemMulti(vectorStyle, vectorStyleId, description, isSelected) {
+
+ /**
+ * Render classification legend when there are conditionals in the vectorstyles
+ * @param {Object} vectorStyle | VectorStyle object
+ * @param {String} id | colormap Id
+ * @param {String} description | Colormap name
+ */
+ renderLegendMultiItem(vectorStyle, vectorStyleId, description) {
const caseDefaultClassName =
- 'wv-palette-selector-row wv-checkbox wv-checkbox-round gray ';
- const checkedClassName = isSelected ? 'checked' : '';
- let array = Array.from(vectorStyle.paint['line-color'] || vectorStyle.paint['circle-color'] || vectorStyle.paint['fill-color']);
- array.shift()
- let organizedArray = [];
- let identifier = '';
+ 'wv-palette-selector-row ';
+ const array = Array.from(vectorStyle.paint['line-color'] || vectorStyle.paint['circle-color'] || vectorStyle.paint['fill-color']);
+ array.shift();
+ const organizedArray = [];
let temp = [];
- let chunk = 2;
+ const chunk = 2;
// https://stackoverflow.com/a/8495740/4589331
for (let i = 0, j = array.length; i < j; i += chunk) {
temp = array.slice(i, i + chunk);
if (temp.length === 2) {
- let obj = {};
+ const obj = {};
if (temp[0].length === 3 &&
- typeof temp[0][2] === "string" &&
- typeof temp[1] === "string"
+ typeof temp[0][2] === 'string' &&
+ typeof temp[1] === 'string'
) {
-
obj.label = temp[0][2];
obj.color = temp[1];
- organizedArray.push(obj)
+ organizedArray.push(obj);
} else {
console.warn('Irregular conditional');
}
- } else if (temp.length === 1 && typeof temp[0] === "string") {
- organizedArray.push({ label: 'Default', color: temp[0] })
+ } else if (temp.length === 1 && typeof temp[0] === 'string') {
+ organizedArray.push({ label: 'Default', color: temp[0] });
} else {
console.warn('Irregular conditional');
}
}
- console.log(organizedArray)
return organizedArray.map((obj, i) => (
- <div key={vectorStyleId + i} className={caseDefaultClassName + checkedClassName}>
- <input
- id={'wv-palette-radio-' + vectorStyleId + '-' + i}
- type="radio"
- name="wv-palette-radio" />
- <label htmlFor={'wv-palette-radio-' + vectorStyleId + '-' + i}>
-
+ <div key={vectorStyleId + i} className={caseDefaultClassName}>
+ <label>
<span
className="wv-palettes-class"
style={{ backgroundColor: obj.color }}
>
&nbsp;
- </span>
+ </span>
<span className="wv-palette-label">{obj.label}</span>
</label>
</div>
)
- )
+ );
}
+
/**
* Render classification customs when there is only one
* Color in colormap
@@ -152,7 +150,7 @@ class VectorStyleSelect extends React.Component {
className="wv-palette-selector settings-component noselect"
id={'wv-palette-selector' + index}
>
- <h2 className="wv-header">Vector Style</h2>
+ <h2 className="wv-header">Vector Styles</h2>
<Scrollbar style={{ maxHeight: '200px' }}>
{uniqueStyleLayers.map(styleLayerObject => {
if (styleLayerObject && styleLayerObject) {