Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WV-3265 Point Sizing for MODIS_Aqua_Thermal_Anomalies_All #5646

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions web/js/components/layer/settings/layer-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { connect } from 'react-redux';

import Opacity from './opacity';
import Palette from './palette';
import Size from './size';
import BandSelection from './band-selection/band-selection-parent-info-menu';
import AssociatedLayers from './associated-layers-toggle';
import VectorStyle from './vector-style';
Expand Down Expand Up @@ -37,6 +38,7 @@ import {
setThresholdRangeAndSquash,
setCustomPalette,
clearCustomPalette,
setSize,
setToggledClassification,
refreshDisabledClassification,
} from '../../../modules/palettes/actions';
Expand Down Expand Up @@ -337,14 +339,17 @@ class LayerSettings extends React.Component {
let renderCustomizations;
const {
setOpacity,
setSize,
customPalettesIsActive,
layer,
palettedAllowed,
zot,
groupName,
} = this.props;
const hasAssociatedLayers = layer.associatedLayers && layer.associatedLayers.length;
const hasTracks = layer.orbitTracks && layer.orbitTracks.length;
const titilerLayer = layer.id === 'HLS_Customizable_Sentinel' || layer.id === 'HLS_Customizable_Landsat';
const pointSizeLayer = layer.type === 'vector' && layer.id === 'MODIS_Aqua_Thermal_Anomalies_All';
const granuleMetadata = layer?.enableCMRDataFinder && !(zot?.underZoomValue > 0);
const layerGroup = layer.layergroup;

Expand All @@ -366,6 +371,15 @@ class LayerSettings extends React.Component {
setOpacity={setOpacity}
layer={layer}
/>
{pointSizeLayer && (
<Size
start={layer.size}
setSize={setSize}
layer={layer}
index={0}
groupName={groupName}
/>
)}
{this.renderGranuleSettings()}
{renderCustomizations}
{titilerLayer && <BandSelection layer={layer} />}
Expand Down Expand Up @@ -447,6 +461,9 @@ const mapDispatchToProps = (dispatch) => ({
setOpacity: (id, opacity) => {
dispatch(setOpacity(id, opacity));
},
setSize: (layerId, size, index, groupName) => {
dispatch(setSize(layerId, size, index, groupName));
},
updateGranuleLayerOptions: (dates, def, count) => {
dispatch(updateGranuleLayerOptions(dates, def, count));
},
Expand Down Expand Up @@ -485,6 +502,7 @@ LayerSettings.propTypes = {
screenHeight: PropTypes.number,
setCustomPalette: PropTypes.func,
setOpacity: PropTypes.func,
setSize: PropTypes.func,
setStyle: PropTypes.func,
setThresholdRange: PropTypes.func,
toggleClassification: PropTypes.func,
Expand Down
58 changes: 58 additions & 0 deletions web/js/components/layer/settings/size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import PropTypes from 'prop-types';
import { debounce } from 'lodash';

class SizeSelect extends React.Component {
christof-wittreich marked this conversation as resolved.
Show resolved Hide resolved
constructor(props) {
super(props);
this.state = {
value: props.start,
};

this.debouncedSetSize = debounce((layerId, size, index, groupName) => {
const { setSize } = this.props;
setSize(layerId, size, index, groupName);
}, 100);
}

render() {
const {
layer,
start,
index,
groupName,
} = this.props;
const { value } = this.state;
return (
<div className="layer-size-select settings-component">
<h2 className="wv-header">Point Size</h2>
<input
type="range"
className="form-range"
min={0}
max={25}
step={5}
defaultValue={start}
onChange={(e) => {
const val = parseFloat(e.target.value);
this.debouncedSetSize(layer.id, val, index, groupName);
this.setState({ value: val });
}}
/>
<div className="wv-label wv-label-size mt-1">
{value <= 0 ? 1 : value}
</div>
</div>
);
}
}
SizeSelect.defaultProps = {
start: 0,
};
SizeSelect.propTypes = {
layer: PropTypes.object,
setSize: PropTypes.func,
start: PropTypes.number,
};

export default SizeSelect;
2 changes: 2 additions & 0 deletions web/js/map/layerbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ export default function mapLayerBuilder(config, cache, store) {
};
if (def.styles) {
parameters.STYLES = def.styles;
} else if (def.size && def.size >= 5) {
parameters.STYLES = `size${def.size}`;
}

urlParameters = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ function UpdateProjection(props) {
case paletteConstants.SET_CUSTOM:
case paletteConstants.SET_DISABLED_CLASSIFICATION:
case paletteConstants.CLEAR_CUSTOM:
case paletteConstants.SET_SIZE:
case layerConstants.ADD_LAYERS_FOR_EVENT:
return setTimeout(reloadLayers, 100);
case vectorStyleConstants.SET_FILTER_RANGE:
Expand Down
1 change: 1 addition & 0 deletions web/js/mapUI/mapUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function MapUI(props) {
case paletteConstants.SET_CUSTOM:
case paletteConstants.SET_DISABLED_CLASSIFICATION:
case paletteConstants.CLEAR_CUSTOM:
case paletteConstants.SET_SIZE:
case layerConstants.ADD_LAYERS_FOR_EVENT:
case vectorStyleConstants.SET_FILTER_RANGE:
case vectorStyleConstants.SET_VECTORSTYLE:
Expand Down
12 changes: 12 additions & 0 deletions web/js/modules/layers/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
CLEAR_CUSTOM as CLEAR_CUSTOM_PALETTE,
SET_THRESHOLD_RANGE_AND_SQUASH,
SET_DISABLED_CLASSIFICATION,
SET_SIZE,
} from '../palettes/constants';
import {
CLEAR_VECTORSTYLE,
Expand Down Expand Up @@ -230,6 +231,17 @@ export function layerReducer(state = initialState, action) {
});
}

case SET_SIZE:
return update(state, {
[compareState]: {
layers: {
[getLayerIndex()]: {
size: { $set: action.size },
},
},
},
});

case SET_FILTER_RANGE: {
return update(state, {
[compareState]: {
Expand Down
12 changes: 12 additions & 0 deletions web/js/modules/layers/reducers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
SET_CUSTOM as SET_CUSTOM_PALETTE,
CLEAR_CUSTOM as CLEAR_CUSTOM_PALETTE,
SET_THRESHOLD_RANGE_AND_SQUASH,
SET_SIZE,
} from '../palettes/constants';

const config = fixtures.config();
Expand Down Expand Up @@ -238,6 +239,17 @@ describe('layer Reducer tests', () => {
expect(getTestLayer(response.active.layers).custom).toEqual(['custom-id']);
});

test('SET_SIZE action sets size for given layer [layers-reducer-set-custom-palette]', () => {
const response = layerReducer(initialState, {
type: SET_SIZE,
id: 'terra-cr',
activeString: 'active',
size: 15,
});

expect(getTestLayer(response.active.layers).size).toEqual(15);
});

test('UPDATE_OPACITY action updates opacity for given layer [layers-reducer-update-opacity]', () => {
const response = layerReducer(initialState, {
type: UPDATE_OPACITY,
Expand Down
1 change: 1 addition & 0 deletions web/js/modules/layers/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function addLayer(id, spec = {}, layersParam, layerConfig, overlayLength,
def.squash = spec.squash || undefined;
def.disabled = spec.disabled || undefined;
def.count = spec.count || def.count || undefined;
def.size = spec.size || undefined;

if (Array.isArray(spec.bandCombo)) {
def.bandCombo = {
Expand Down
7 changes: 6 additions & 1 deletion web/js/modules/layers/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ export function serializeLayers(layers, state, groupName) {
value: bandComboString,
});
}
if (def.palette && (def.custom || def.min || def.max || def.squash || def.disabled || (palettes[def.id] && palettes[def.id].maps && palettes[def.id].maps.length > 1))) {
if (def.palette && (def.custom || def.min || def.max || def.squash || def.disabled || def.size || (palettes[def.id] && palettes[def.id].maps && palettes[def.id].maps.length > 1))) {
// If layer has palette and palette attributes
const paletteAttributeArray = getPaletteAttributeArray(
def.id,
Expand Down Expand Up @@ -913,6 +913,7 @@ const getLayerSpec = (attributes) => {
let custom;
let disabled;
let count;
let size;
let bandCombo;

lodashEach(attributes, (attr) => {
Expand Down Expand Up @@ -1008,13 +1009,17 @@ const getLayerSpec = (attributes) => {
if (attr.id === 'count') {
count = Number(attr.value);
}
if (attr.id === 'size') {
size = attr.value;
}
});

return {
hidden,
opacity,
count,
bandCombo,
size,

// only include palette attributes if Array.length condition
// is true: https://stackoverflow.com/a/40560953/4589331
Expand Down
3 changes: 3 additions & 0 deletions web/js/modules/map/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ export async function promiseImageryForTour(state, layers, dateString, activeStr
if (layer.squash) {
keys.push('squash');
}
if (layer.size) {
keys.push(`size=${layer.size}`);
}
if (keys.length > 0) {
options.style = keys.join(',');
}
Expand Down
23 changes: 23 additions & 0 deletions web/js/modules/palettes/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SET_THRESHOLD_RANGE_AND_SQUASH,
CLEAR_CUSTOM,
SET_CUSTOM,
SET_SIZE,
SET_DISABLED_CLASSIFICATION,
LOADED_CUSTOM_PALETTES,
} from './constants';
Expand All @@ -17,6 +18,7 @@ import {
clearCustomSelector,
refreshDisabledSelector,
setDisabledSelector,
setSize as setSizeSelector,
} from './selectors';

/**
Expand Down Expand Up @@ -122,6 +124,27 @@ export function clearCustomPalette(layerId, index, groupName) {
};
}

export function setSize(layerId, size, index, groupName) {
return (dispatch, getState) => {
const state = getState();
const newActivePalettesObj = setSizeSelector(
layerId,
size,
index,
state.palettes[groupName],
state,
);
dispatch({
type: SET_SIZE,
groupName,
activeString: groupName,
layerId,
palettes: newActivePalettesObj,
size,
});
};
}

export function setToggledClassification(layerId, classIndex, index, groupName) {
return (dispatch, getState) => {
const state = getState();
Expand Down
13 changes: 13 additions & 0 deletions web/js/modules/palettes/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
setThresholdRangeAndSquash,
setCustomPalette,
clearCustomPalette,
setSize,
} from './actions';
import { addLayer } from '../layers/selectors';
import {
Expand All @@ -18,6 +19,7 @@ import {
SET_THRESHOLD_RANGE_AND_SQUASH,
SET_CUSTOM,
CLEAR_CUSTOM,
SET_SIZE,
} from './constants';
import fixtures from '../../fixtures';

Expand Down Expand Up @@ -256,4 +258,15 @@ describe('Test lookup actions [palettes-actions-lookup]', () => {
);
},
);
test(`test ${setSize} action [palettes-actions-set-size]`, () => {
const store = mockStore(stateWithLayers);
store.dispatch(setSize('terra-aod', 15, 0, 'active'));
const response = store.getActions()[0];

expect(response.type).toEqual(SET_SIZE);
expect(response.size).toEqual(15);
expect(response.groupName).toEqual('active');
expect(response.layerId).toEqual('terra-aod');
expect(response.activeString).toEqual('active');
});
});
4 changes: 3 additions & 1 deletion web/js/modules/palettes/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const SET_THRESHOLD_RANGE_AND_SQUASH = 'PALETTES/SET_THRESHOLD_RANGE_AND_
export const CLEAR_CUSTOM = 'PALETTES/CLEAR_CUSTOM';
export const CLEAR_CUSTOMS = 'PALETTES/CLEAR_CUSTOMS';
export const SET_CUSTOM = 'PALETTES/SET_CUSTOM';
export const SET_SIZE = 'PALETTES/SET_SIZE';
export const LOADED_CUSTOM_PALETTES = 'PALETTES/LOADED_CUSTOM_PALETTES';
export const BULK_PALETTE_RENDERING_SUCCESS = 'PALETTES/BULK_PALETTE_RENDERING_SUCCESS';
export const BULK_PALETTE_PRELOADING_SUCCESS = 'PALETTES/BULK_PALETTE_PRELOADING_SUCCESS';
Expand All @@ -18,5 +19,6 @@ export const PALETTE_STRINGS_PERMALINK_ARRAY = [
'min',
'max',
'disabled',
'size',
];
export const CUSTOM_PALETTE_TYPE_ARRAY = ['custom', 'squash', 'min', 'max', 'disabled'];
export const CUSTOM_PALETTE_TYPE_ARRAY = ['custom', 'squash', 'min', 'max', 'disabled', 'size'];
2 changes: 2 additions & 0 deletions web/js/modules/palettes/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BULK_PALETTE_PRELOADING_SUCCESS,
CLEAR_CUSTOM,
SET_DISABLED_CLASSIFICATION,
SET_SIZE,
} from './constants';
import { INIT_SECOND_LAYER_GROUP } from '../layers/constants';

Expand Down Expand Up @@ -70,6 +71,7 @@ export function paletteReducer(state = defaultPaletteState, action) {
case SET_CUSTOM:
case SET_DISABLED_CLASSIFICATION:
case CLEAR_CUSTOM:
case SET_SIZE:
return lodashAssign({}, state, {
[groupName]: action.palettes || {},
});
Expand Down
Loading
Loading