Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

props destructure, remove lodash, some other minor changes

VictorSf618067b894d
diff --git a/web/js/components/layer/settings/palette.js b/web/js/components/layer/settings/palette.js
index e53762142..b43b85b88 100644
--- a/web/js/components/layer/settings/palette.js
+++ b/web/js/components/layer/settings/palette.js
@@ -1,23 +1,24 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
-import lodashIndexOf from 'lodash/indexOf';
import { drawPaletteOnCanvas } from '../../../modules/palettes/util';
import util from '../../../util/util';
import Scrollbar from '../../util/scrollbar';
-const PaletteSelect = function ({
- activePalette: initialActivePalette,
- canvas,
- clearCustomPalette,
- getCustomPalette,
- getDefaultLegend,
- groupName,
- index,
- layer,
- paletteOrder,
- palettesTranslate,
- setCustomPalette,
-}) {
+function PaletteSelect (props) {
+ const {
+ activePalette: initialActivePalette,
+ canvas,
+ clearCustomPalette,
+ getCustomPalette,
+ getDefaultLegend,
+ groupName,
+ index,
+ layer,
+ paletteOrder,
+ palettesTranslate,
+ setCustomPalette,
+ } = props
+
const [activePalette, setActivePalette] = useState(initialActivePalette);
const renderDefault = () => {
@@ -39,11 +40,9 @@ const PaletteSelect = function ({
};
const onChangePalette = (id) => {
- if (id === '__default') {
- clearCustomPalette(layer.id, index, groupName);
- } else {
+ id === '__default' ?
+ clearCustomPalette(layer.id, index, groupName) :
setCustomPalette(layer.id, id, index, groupName);
- }
setActivePalette(id);
};
@@ -52,10 +51,8 @@ const PaletteSelect = function ({
const target = getCustomPalette(id);
const targetType = target.colors.length === 1 ? 'classification' : 'continuous';
- if (
- (source.type === 'continuous' && targetType === 'continuous')
- || (source.type === 'discrete' && targetType === 'continuous')
- ) {
+ if ((source.type === 'continuous' && targetType === 'continuous') ||
+ (source.type === 'discrete' && targetType === 'continuous')) {
const translated = palettesTranslate(source.colors, target.colors);
return renderSelectorItemScale(
translated,
@@ -142,7 +139,7 @@ const PaletteSelect = function ({
{
// eslint-disable-next-line array-callback-return
paletteOrder.map((id) => {
- if (lodashIndexOf(recommended, id) < 0) {
+ if (recommended.indexOf(id) < 0) {
const item = customLegend(id);
if (item) {
return item;
@@ -155,194 +152,6 @@ const PaletteSelect = function ({
);
};
-// class PaletteSelect extends React.Component {
-// constructor(props) {
-// super(props);
-// this.state = {
-// activePalette: props.activePalette,
-// };
-// }
-
-// /**
-// * Render default legend option
-// */
-// renderDefault() {
-// const { layer, index, getDefaultLegend } = this.props;
-// const { activePalette } = this.state;
-// const legend = getDefaultLegend(layer.id, index);
-// if (legend.type === 'continuous' || legend.type === 'discrete') {
-// return this.renderSelectorItemScale(
-// legend.colors,
-// '__default',
-// legend,
-// activePalette === '__default',
-// );
-// }
-// return this.renderSelectorItemSingle(
-// legend,
-// '__default',
-// 'Default',
-// activePalette === '__default',
-// );
-// }
-
-// /**
-// * Pass palette to model after selection
-// * @param {String} id | custom Palette Id
-// */
-// onChangePalette(id) {
-// const {
-// layer, clearCustomPalette, setCustomPalette, groupName, index,
-// } = this.props;
-
-// // Applying customs takes a while and
-// // it looks more natural to make this async
-// // instead of waiting
-// if (id === '__default') {
-// clearCustomPalette(layer.id, index, groupName);
-// } else {
-// setCustomPalette(layer.id, id, index, groupName);
-// }
-// this.setState({ activePalette: id });
-// }
-
-// /**
-// * Apply logic to render correct palette selection
-// * @param {String} id | Legend Id
-// */
-// customLegend(id) {
-// const {
-// getDefaultLegend,
-// getCustomPalette,
-// layer,
-// index,
-// palettesTranslate,
-// } = this.props;
-// const { activePalette } = this.state;
-// const source = getDefaultLegend(layer.id, index);
-// const target = getCustomPalette(id);
-// const targetType = target.colors.length === 1 ? 'classification' : 'continuous';
-
-// if (
-// (source.type === 'continuous' && targetType === 'continuous')
-// || (source.type === 'discrete' && targetType === 'continuous')
-// ) {
-// const translated = palettesTranslate(source.colors, target.colors);
-// return this.renderSelectorItemScale(
-// translated,
-// id,
-// target,
-// activePalette === target.id,
-// );
-// }
-// if (source.type === 'classification' && targetType === 'classification') {
-// return this.renderSelectorItemSingle(
-// target,
-// id,
-// target.name,
-// activePalette === target.id,
-// );
-// }
-// }
-
-// /**
-// * Render customs palette options
-// * @param {Object} palette | Palette object
-// * @param {String} id | colormap Id
-// * @param {Object} legend | Legend Object
-// * @param {Boolean} isSelected | is this colormap active
-// */
-// renderSelectorItemScale(palette, id, legend, isSelected) {
-// const { canvas } = this.props;
-// const caseDefaultClassName = 'wv-palette-selector-row wv-checkbox wv-checkbox-round gray ';
-// const checkedClassName = isSelected ? 'checked' : '';
-// const ctx = canvas.getContext('2d');
-// drawPaletteOnCanvas(
-// ctx,
-// palette,
-// canvas.width,
-// canvas.height,
-// );
-// return (
-// <div key={id} className={caseDefaultClassName + checkedClassName}>
-// <input
-// id={`wv-palette-radio-${id}`}
-// type="radio"
-// name="wv-palette-radio"
-// onClick={() => this.onChangePalette(id)}
-// />
-// <label htmlFor={`wv-palette-radio-${id}`}>
-// <img src={canvas.toDataURL('image/png')} />
-// <span className="wv-palette-label">{legend.name || 'Default'}</span>
-// </label>
-// </div>
-// );
-// }
-
-// /**
-// * Render classification customs when there is only one
-// * Color in colormap
-// * @param {Object} palette | Palette object
-// * @param {String} id | colormap Id
-// * @param {String} description | Colormap name
-// * @param {Boolean} isSelected | is this colormap active
-// */
-// renderSelectorItemSingle(palette, id, description, isSelected) {
-// const color = palette.classes
-// ? palette.classes.colors[0]
-// : palette.colors[0];
-// const caseDefaultClassName = 'wv-palette-selector-row wv-checkbox wv-checkbox-round gray ';
-// const checkedClassName = isSelected ? 'checked' : '';
-// const isInvisible = color === '00000000';
-
-// return (
-// <div key={id} className={caseDefaultClassName + checkedClassName}>
-// <input
-// id={`wv-palette-radio-${id}`}
-// type="radio"
-// name="wv-palette-radio"
-// onClick={() => this.onChangePalette(id)}
-// />
-// <label htmlFor={`wv-palette-radio-${id}`}>
-// <span
-// className={isInvisible ? 'checkerbox-bg wv-palettes-class' : 'wv-palettes-class'}
-// style={isInvisible ? null : { backgroundColor: util.hexToRGBA(color) }}
-// >
-// &nbsp;
-// </span>
-// <span className="wv-palette-label">{description}</span>
-// </label>
-// </div>
-// );
-// }
-
-// render() {
-// const { index, layer, paletteOrder } = this.props;
-// const recommended = layer.palette.recommended || [];
-// return (
-// <div
-// className="wv-palette-selector settings-component noselect"
-// id={`wv-palette-selector${index}`}
-// >
-// <h2 className="wv-header">Color Palette</h2>
-// <Scrollbar style={{ maxHeight: '200px' }}>
-// {this.renderDefault()}
-// {
-// // eslint-disable-next-line array-callback-return
-// paletteOrder.map((id) => {
-// if (lodashIndexOf(recommended, id) < 0) {
-// const item = this.customLegend(id);
-// if (item) {
-// return item;
-// }
-// }
-// })
-// }
-// </Scrollbar>
-// </div>
-// );
-// }
-// }
PaletteSelect.propTypes = {
activePalette: PropTypes.string,
canvas: PropTypes.object,