Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

utilize getActiveLayers and getCurrentDate throughout

Jason Kent276d869e577c
diff --git a/web/js/components/layer/product-picker/browse/measurement-layer-row.js b/web/js/components/layer/product-picker/browse/measurement-layer-row.js
index 2c4ad4ced..2eb4718c4 100644
--- a/web/js/components/layer/product-picker/browse/measurement-layer-row.js
+++ b/web/js/components/layer/product-picker/browse/measurement-layer-row.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { ListGroupItem, UncontrolledTooltip } from 'reactstrap';
import { connect } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { available, getActiveLayers } from '../../../../modules/layers/selectors';
+import { available, getActiveLayersMap } from '../../../../modules/layers/selectors';
import Checkbox from '../../../util/checkbox';
import {
addLayer as addLayerAction,
@@ -101,7 +101,7 @@ MeasurementLayerRow.propTypes = {
const mapStateToProps = (state, ownProps) => {
const { notifications, browser } = state;
- const activeLayerMap = getActiveLayers(state);
+ const activeLayerMap = getActiveLayersMap(state);
const { id } = ownProps.layer;
return {
isEnabled: !!activeLayerMap[id],
diff --git a/web/js/components/layer/product-picker/search/layer-metadata-detail.js b/web/js/components/layer/product-picker/search/layer-metadata-detail.js
index 0cd3458fd..f71ffbc7b 100644
--- a/web/js/components/layer/product-picker/search/layer-metadata-detail.js
+++ b/web/js/components/layer/product-picker/search/layer-metadata-detail.js
@@ -12,7 +12,7 @@ import {
import {
selectLayer as selectLayerAction,
} from '../../../../modules/product-picker/actions';
-import { getActiveLayers } from '../../../../modules/layers/selectors';
+import { getActiveLayersMap } from '../../../../modules/layers/selectors';
import RenderSplitLayerTitle from '../renderSplitTitle';
import RecentLayersInfo from '../browse/recent-layers-info';
@@ -225,7 +225,7 @@ const mapStateToProps = (state) => {
config,
} = state;
const { selectedLayer, categoryType } = productPicker;
- const activeLayers = getActiveLayers(state);
+ const activeLayers = getActiveLayersMap(state);
const isActive = selectedLayer && !!activeLayers[selectedLayer.id];
return {
layer: selectedLayer,
diff --git a/web/js/components/layer/product-picker/search/search-layer-row.js b/web/js/components/layer/product-picker/search/search-layer-row.js
index 262bde22f..21d7481f9 100644
--- a/web/js/components/layer/product-picker/search/search-layer-row.js
+++ b/web/js/components/layer/product-picker/search/search-layer-row.js
@@ -10,7 +10,7 @@ import {
import {
clearSingleRecentLayer as clearSingleRecentLayerAction,
} from '../../../../modules/product-picker/actions';
-import { getActiveLayers } from '../../../../modules/layers/selectors';
+import { getActiveLayersMap } from '../../../../modules/layers/selectors';
import RenderSplitLayerTitle from '../renderSplitTitle';
import getSelectedDate from '../../../../modules/date/selectors';
import { getLayerNoticesForLayer } from '../../../../modules/notifications/util';
@@ -180,7 +180,7 @@ SearchLayerRow.propTypes = {
const mapStateToProps = (state, ownProps) => {
const { productPicker, browser, notifications } = state;
- const activeLayerMap = getActiveLayers(state);
+ const activeLayerMap = getActiveLayersMap(state);
const { categoryType, selectedLayer } = productPicker;
return {
scrollIntoView: browser.screenWidth < 1024,
diff --git a/web/js/components/layer/settings/orbit-tracks-toggle.js b/web/js/components/layer/settings/orbit-tracks-toggle.js
index 225783fef..a34c1c049 100644
--- a/web/js/components/layer/settings/orbit-tracks-toggle.js
+++ b/web/js/components/layer/settings/orbit-tracks-toggle.js
@@ -7,7 +7,7 @@ import {
removeLayer as removeLayerAction,
} from '../../../modules/layers/actions';
import { getOrbitTrackTitle } from '../../../modules/layers/util';
-import { getActiveLayers } from '../../../modules/layers/selectors';
+import { getActiveLayersMap } from '../../../modules/layers/selectors';
const OrbitTracksToggle = (props) => {
const {
@@ -44,7 +44,7 @@ const mapStateToProps = (state, ownProps) => {
const { tracks } = ownProps.layer;
return {
trackLayers: tracks.map((trackName) => config.layers[trackName]),
- activeLayers: getActiveLayers(state),
+ activeLayers: getActiveLayersMap(state),
};
};
diff --git a/web/js/components/timeline/timeline-data/timeline-data.js b/web/js/components/timeline/timeline-data/timeline-data.js
index b53550e58..2d9da3a73 100644
--- a/web/js/components/timeline/timeline-data/timeline-data.js
+++ b/web/js/components/timeline/timeline-data/timeline-data.js
@@ -13,6 +13,7 @@ import {
filterProjLayersWithStartDate,
getMaxLayerEndDates,
} from '../../../modules/date/util';
+import { getActiveLayers } from '../../../modules/layers/selectors';
import Scrollbars from '../../util/scrollbar';
import Switch from '../../util/switch';
import DataItemList from './data-item-list';
@@ -370,7 +371,6 @@ class TimelineData extends Component {
function mapStateToProps(state) {
const {
- compare,
date,
layers,
modal,
@@ -381,7 +381,7 @@ function mapStateToProps(state) {
} = date;
// handle active layer filtering
- const activeLayers = layers[compare.activeString];
+ const activeLayers = getActiveLayers(state);
const projection = proj.id;
const activeLayersFiltered = filterProjLayersWithStartDate(activeLayers, projection);
diff --git a/web/js/containers/alerts.js b/web/js/containers/alerts.js
index 754b0ed2d..4c6445d13 100644
--- a/web/js/containers/alerts.js
+++ b/web/js/containers/alerts.js
@@ -7,6 +7,7 @@ import { openCustomContent } from '../modules/modal/actions';
import { hasVectorLayers } from '../modules/layers/util';
import { DISABLE_VECTOR_ALERT, MODAL_PROPERTIES } from '../modules/alerts/constants';
import safeLocalStorage from '../util/local-storage';
+import { getActiveLayers } from '../modules/layers/selectors';
const HAS_LOCAL_STORAGE = safeLocalStorage.enabled;
const { DISMISSED_COMPARE_ALERT, DISMISSED_EVENT_VIS_ALERT } = safeLocalStorage.keys;
@@ -81,16 +82,16 @@ const mapDispatchToProps = (dispatch) => ({
});
const mapStateToProps = (state) => {
const {
- browser, events, sidebar, compare, layers, alerts,
+ browser, events, sidebar, compare, alerts,
} = state;
- const { activeString } = compare;
const { isVectorAlertActive } = alerts;
+ const activeLayers = getActiveLayers(state);
return {
isSmall: browser.lessThan.small,
isEventsActive: !!(events.selected.id && sidebar.activeTab === 'events'),
isCompareActive: compare.active,
- isVectorAlertPresent: hasVectorLayers(layers[activeString]) && isVectorAlertActive,
+ isVectorAlertPresent: hasVectorLayers(activeLayers) && isVectorAlertActive,
};
};
export default connect(
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.js
index dc5db975c..fcc9c27d0 100644
--- a/web/js/containers/animation-widget.js
+++ b/web/js/containers/animation-widget.js
@@ -41,8 +41,10 @@ import {
import {
hasSubDaily as hasSubDailySelector,
getLayers,
+ getActiveLayers,
dateRange as getDateRange,
} from '../modules/layers/selectors';
+import getSelectedDate from '../modules/date/selectors';
import {
play,
onClose,
@@ -619,7 +621,6 @@ class AnimationWidget extends React.Component {
function mapStateToProps(state) {
const {
- layers,
compare,
animation,
date,
@@ -645,17 +646,16 @@ function mapStateToProps(state) {
interval,
customInterval,
} = date;
- const activeStr = compare.activeString;
- const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
- const hasSubdailyLayers = hasSubDailySelector(layers[activeStr]);
+ const activeLayers = getActiveLayers(state);
+ const hasSubdailyLayers = hasSubDailySelector(activeLayers);
const activeLayersForProj = getLayers(
- layers[activeStr],
+ activeLayers,
{ proj: proj.id },
state,
);
const hasFutureLayers = activeLayersForProj.filter((layer) => layer.futureTime).length > 0;
const layerDateRange = getDateRange({}, activeLayersForProj);
- const activePalettes = palettes[activeStr];
+ const activePalettes = palettes[compare.activeString];
const hasCustomPalettes = hasCustomPaletteInActiveProjection(
activeLayersForProj,
activePalettes,
@@ -698,7 +698,7 @@ function mapStateToProps(state) {
startDate,
endDate,
activePalettes,
- currentDate: date[activeDateStr],
+ currentDate: getSelectedDate(state),
minDate,
maxDate,
isActive: animationIsActive,
@@ -711,7 +711,7 @@ function mapStateToProps(state) {
customInterval: customInterval || 3,
numberOfFrames,
sliderLabel: 'Frames Per Second',
- layers: getLayers(layers[activeStr], {}, state),
+ layers: getLayers(activeLayers, {}, state),
speed,
isPlaying,
looping: loop,
@@ -724,7 +724,7 @@ function mapStateToProps(state) {
rotation,
hasGraticule: Boolean(
lodashGet(
- lodashFind(layers[activeStr], { id: 'Graticule' }) || {},
+ lodashFind(activeLayers, { id: 'Graticule' }) || {},
'visible',
),
),
diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.js
index ed833e439..2f77e5a3a 100644
--- a/web/js/containers/image-download.js
+++ b/web/js/containers/image-download.js
@@ -15,7 +15,9 @@ import util from '../util/util';
import {
hasSubDaily as hasSubDailySelector,
getLayers,
+ getActiveLayers,
} from '../modules/layers/selectors';
+import getSelectedDate from '../modules/date/selectors';
import {
resolutionsGeo,
resolutionsPolar,
@@ -156,9 +158,6 @@ function mapStateToProps(state) {
proj,
browser,
geosearch,
- layers,
- compare,
- date,
map,
imageDownload,
} = state;
@@ -167,9 +166,8 @@ function mapStateToProps(state) {
} = imageDownload;
const { screenWidth, screenHeight } = browser;
const markerCoordinates = geosearch.coordinates;
- const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
- const activeStr = compare.activeString;
- const hasSubdailyLayers = hasSubDailySelector(layers[activeStr]);
+ const activeLayers = getActiveLayers(state);
+ const hasSubdailyLayers = hasSubDailySelector(activeLayers);
let url = DEFAULT_URL;
if (config.features.imageDownload && config.features.imageDownload.url) {
url = config.features.imageDownload.url;
@@ -191,9 +189,9 @@ function mapStateToProps(state) {
boundaries,
hasSubdailyLayers,
markerCoordinates,
- date: date[activeDateStr],
+ date: getSelectedDate(state),
getLayers: () => getLayers(
- layers[compare.activeString],
+ getActiveLayers(state),
{
reverse: true,
renderable: true,
diff --git a/web/js/containers/map-interactions/ol-vector-interactions.js b/web/js/containers/map-interactions/ol-vector-interactions.js
index db919d761..1800e4d87 100644
--- a/web/js/containers/map-interactions/ol-vector-interactions.js
+++ b/web/js/containers/map-interactions/ol-vector-interactions.js
@@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
import { transform } from 'ol/proj';
import { isFromActiveCompareRegion } from '../../modules/compare/util';
import { hasNonClickableVectorLayer } from '../../modules/layers/util';
+import { getActiveLayers } from '../../modules/layers/selectors';
import vectorDialog from '../vector-dialog';
import { onMapClickGetVectorFeatures } from '../../modules/vector-styles/util';
import { openCustomContent, onClose } from '../../modules/modal/actions';
@@ -107,10 +108,10 @@ export class VectorInteractions extends React.Component {
function mapStateToProps(state) {
const {
- modal, map, measure, vectorStyles, browser, compare, proj, ui, layers,
+ modal, map, measure, vectorStyles, browser, compare, proj, ui,
} = state;
let swipeOffset;
- const activeLayers = layers[compare.activeString];
+ const activeLayers = getActiveLayers(state);
if (compare.active && compare.mode === 'swipe') {
const percentOffset = state.compare.value || 50;
swipeOffset = browser.screenWidth * (percentOffset / 100);
diff --git a/web/js/containers/sidebar/compare.js b/web/js/containers/sidebar/compare.js
index 49bd4fd75..60a0b0eb7 100644
--- a/web/js/containers/sidebar/compare.js
+++ b/web/js/containers/sidebar/compare.js
@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import {
Nav, NavItem, NavLink, TabContent, TabPane,
} from 'reactstrap';
-import Layers from './layers';
+import LayersContainer from './layers-container';
import { getLayers } from '../../modules/layers/selectors';
import { toggleActiveCompareState as toggleActiveCompareStateAction } from '../../modules/compare/actions';
import util from '../../util/util';
@@ -59,7 +59,7 @@ const CompareCase = (props) => {
</Nav>
<TabContent activeTab={isCompareA ? '1' : '2'}>
<TabPane tabId="1">
- <Layers
+ <LayersContainer
isActive={isCompareA}
activeOverlays={layersA}
compareState="active"
@@ -67,7 +67,7 @@ const CompareCase = (props) => {
/>
</TabPane>
<TabPane tabId="2">
- <Layers
+ <LayersContainer
isActive={!isCompareA}
activeOverlays={layersB}
compareState="activeB"
diff --git a/web/js/containers/sidebar/data.js b/web/js/containers/sidebar/data.js
index 5a6adcb29..dd4800bd5 100644
--- a/web/js/containers/sidebar/data.js
+++ b/web/js/containers/sidebar/data.js
@@ -11,7 +11,7 @@ import {
} from '../../modules/data/selectors';
import { selectProduct } from '../../modules/data/actions';
import { openCustomContent } from '../../modules/modal/actions';
-import { getLayers } from '../../modules/layers/selectors';
+import { getLayers, getActiveLayers } from '../../modules/layers/selectors';
const CustomBodyModalContent = () => (
<>
@@ -129,11 +129,13 @@ const mapDispatchToProps = (dispatch) => ({
function mapStateToProps(state, ownProps) {
const { tabTypes } = ownProps;
const {
- layers, proj, data, config, compare, sidebar,
+ proj, data, config, sidebar,
} = state;
const { selectedProduct, selectedGranules } = data;
- const { activeString } = compare;
- const activeLayers = getLayers(layers[activeString], { proj: proj.id });
+ const activeLayers = getLayers(
+ getActiveLayers(state),
+ { proj: proj.id },
+ );
const counts = getSelectionCounts(activeLayers, selectedGranules);
const products = getDataProductsFromActiveLayers(
activeLayers,
diff --git a/web/js/containers/sidebar/footer-content.js b/web/js/containers/sidebar/footer-content.js
index 811411be0..292221808 100644
--- a/web/js/containers/sidebar/footer-content.js
+++ b/web/js/containers/sidebar/footer-content.js
@@ -16,6 +16,7 @@ import { openCustomContent } from '../../modules/modal/actions';
import { toggleListAll } from '../../modules/natural-events/actions';
import { DATA_GET_DATA_CLICK } from '../../modules/data/constants';
import { stop as stopAnimationAction } from '../../modules/animation/actions';
+import { getActiveLayers } from '../../modules/layers/selectors';
class FooterContent extends React.Component {
constructor(props) {
@@ -174,14 +175,12 @@ const mapDispatchToProps = (dispatch) => ({
});
function mapStateToProps(state) {
const {
- requestedEvents, config, layers, data, compare, browser,
+ requestedEvents, config, data, compare, browser,
} = state;
const { showAll } = state.events;
const { selectedGranules } = data;
const events = lodashGet(requestedEvents, 'response');
- const { activeString } = compare;
- const activeLayers = layers[activeString];
- const counts = getSelectionCounts(activeLayers, selectedGranules);
+ const counts = getSelectionCounts(getActiveLayers(state), selectedGranules);
const dataSelectionSize = getDataSelectionSize(selectedGranules);
return {
diff --git a/web/js/containers/sidebar/layer-list.js b/web/js/containers/sidebar/layer-list.js
index 7406e171c..696553faa 100644
--- a/web/js/containers/sidebar/layer-list.js
+++ b/web/js/containers/sidebar/layer-list.js
@@ -4,11 +4,12 @@ import { connect } from 'react-redux';
import { Droppable, DragDropContext } from 'react-beautiful-dnd';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { get as lodashGet } from 'lodash';
-import Layer from './layer';
+import LayerRow from './layer-row';
import {
replaceSubGroup,
getZotsForActiveLayers,
getTitles,
+ getActiveLayers,
memoizedAvailable as availableSelector,
} from '../../modules/layers/selectors';
import { reorderLayers as reorderLayersAction } from '../../modules/layers/actions';
@@ -28,7 +29,6 @@ function LayerList(props) {
activeLayers,
layers,
zots,
- runningLayers,
projId,
getNames,
available,
@@ -71,7 +71,7 @@ function LayerList(props) {
const { id, projections, visible } = layer;
return (
- <Layer
+ <LayerRow
layer={layer}
compareState={compareState}
isInProjection={!!projections[projId]}
@@ -82,7 +82,6 @@ function LayerList(props) {
names={getNames(id)}
isDisabled={!available(id)}
isVisible={visible}
- runningObject={runningLayers && runningLayers[id]}
/>
);
};
@@ -105,7 +104,6 @@ function LayerList(props) {
>
{(provided, snapshot) => (
<ul
- id={groupId}
className="category"
ref={provided.innerRef}
// eslint-disable-next-line react/jsx-props-no-spreading
@@ -138,22 +136,15 @@ LayerList.propTypes = {
};
const mapStateToProps = (state, ownProps) => {
- const { compareState } = ownProps;
- const {
- proj, config, map,
- } = state;
- const { runningLayers } = state.layers;
- const { id } = proj;
- const activeLayers = state.layers[compareState];
+ const { proj, config, map } = state;
const zots = lodashGet(map, 'ui.selected')
? getZotsForActiveLayers(state)
: {};
return {
zots,
- activeLayers,
- runningLayers,
- projId: id,
- getNames: (layerId) => getTitles(config, layerId, id),
+ activeLayers: getActiveLayers(state),
+ projId: proj.id,
+ getNames: (layerId) => getTitles(config, layerId, proj.id),
available: (layerId) => availableSelector(state)(layerId),
};
};
diff --git a/web/js/containers/sidebar/layer.js b/web/js/containers/sidebar/layer-row.js
similarity index 97%
rename from web/js/containers/sidebar/layer.js
rename to web/js/containers/sidebar/layer-row.js
index 47cf4d71d..08d4c73f3 100644
--- a/web/js/containers/sidebar/layer.js
+++ b/web/js/containers/sidebar/layer-row.js
@@ -28,6 +28,7 @@ import OrbitTrack from './orbit-track';
import Zot from './zot';
import { isVectorLayerClickable } from '../../modules/layers/util';
import { MODAL_PROPERTIES } from '../../modules/alerts/constants';
+import { getActiveLayers } from '../../modules/layers/selectors';
const { vectorModalProps } = MODAL_PROPERTIES;
@@ -40,7 +41,7 @@ const getItemStyle = (isDragging, draggableStyle) => ({
left: null,
});
-class Layer extends React.Component {
+class LayerRow extends React.Component {
getPaletteLegend = () => {
const {
compare,
@@ -308,18 +309,14 @@ class Layer extends React.Component {
}
}
-Layer.defaultProps = {
- palette: {},
-};
-
-function mapStateToProps(state, ownProps) {
+const mapStateToProps = (state, ownProps) => {
const {
layer,
isVisible,
compareState,
} = ownProps;
const {
- palettes, config, map, layers, compare, proj,
+ palettes, config, map, compare, proj,
} = state;
const hasPalette = !lodashIsEmpty(layer.palette);
const renderedPalettes = palettes.rendered;
@@ -328,10 +325,12 @@ function mapStateToProps(state, ownProps) {
? getPaletteLegends(layer.id, compareState, state)
: [];
const isCustomPalette = hasPalette && palettes.custom[layer.id];
- const tracksForLayer = layers[compareState].filter((activeLayer) => (layer.tracks || []).some((track) => activeLayer.id === track));
const selectedMap = lodashGet(map, 'ui.selected');
const isVector = layer.type === 'vector';
const mapRes = selectedMap ? selectedMap.getView().getResolution() : null;
+ const tracksForLayer = getActiveLayers(state).filter(
+ (activeLayer) => (layer.tracks || []).some((track) => activeLayer.id === track),
+ );
return {
compare,
@@ -349,7 +348,7 @@ function mapStateToProps(state, ownProps) {
getPalette: (layerId, i) => getPalette(layer.id, i, compareState, state),
runningObject: map.runningDataObj[layer.id],
};
-}
+};
const mapDispatchToProps = (dispatch) => ({
hover: (id, value) => {
@@ -412,11 +411,17 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(requestPalette(id));
},
});
+
export default connect(
mapStateToProps,
mapDispatchToProps,
-)(Layer);
-Layer.propTypes = {
+)(LayerRow);
+
+LayerRow.defaultProps = {
+ palette: {},
+};
+
+LayerRow.propTypes = {
compare: PropTypes.object,
getPalette: PropTypes.func,
hasPalette: PropTypes.bool,
diff --git a/web/js/containers/sidebar/layers-container.js b/web/js/containers/sidebar/layers-container.js
new file mode 100644
index 000000000..daf96fba2
--- /dev/null
+++ b/web/js/containers/sidebar/layers-container.js
@@ -0,0 +1,148 @@
+/* eslint-disable react/jsx-props-no-spreading */
+import React from 'react';
+import { connect } from 'react-redux';
+import { Draggable, Droppable, DragDropContext } from 'react-beautiful-dnd';
+import PropTypes from 'prop-types';
+import LayerList from './layer-list';
+import { getLayers, getActiveLayers } from '../../modules/layers/selectors';
+import Scrollbars from '../../components/util/scrollbar';
+
+const reorder = (list, startIndex, endIndex) => {
+ const result = Array.from(list);
+ const [removed] = result.splice(startIndex, 1);
+ result.splice(endIndex, 0, removed);
+ return result;
+};
+
+const getGroupedLayers = (layers) => {
+ const allGroupsMap = {};
+ layers.forEach((layer) => {
+ const { layergroup } = layer;
+ if (layergroup && layergroup.length) {
+ // TODO just using first group in array for now
+ const [groupName] = layergroup;
+ if (allGroupsMap[groupName]) {
+ allGroupsMap[groupName].push(layer);
+ } else {
+ allGroupsMap[groupName] = [layer];
+ }
+ }
+ });
+ return Object.keys(allGroupsMap).map((group) => ({
+ groupName: group,
+ layers: allGroupsMap[group],
+ }));
+};
+
+function LayersContainer (props) {
+ const {
+ overlayGroups,
+ baselayers,
+ isActive,
+ compareState,
+ height,
+ layerSplit,
+ } = props;
+ const outterClass = 'layer-container sidebar-panel';
+
+ const renderLayerList = (group, idx) => {
+ const { groupName, layers } = group;
+ return ((
+ <Draggable
+ key={groupName}
+ draggableId={groupName}
+ index={idx}
+ >
+ {(provided) => (
+ <li
+ id={`${compareState}-${groupName}`}
+ ref={provided.innerRef}
+ {...provided.draggableProps}
+ {...provided.dragHandleProps}
+ >
+ <LayerList
+ title={groupName}
+ groupId={groupName}
+ compareState={compareState}
+ layerSplit={layerSplit}
+ layers={layers}
+ />
+ </li>
+ )}
+ </Draggable>
+ ));
+ };
+
+ /**
+ * Update layer group order after drag/drop
+ * @param {*} result
+ */
+ const onDragEnd = (result) => {
+ const { destination, source } = result;
+ if (!destination || source.index === destination.index) {
+ return;
+ }
+ reorder(overlayGroups, source.index, destination.index);
+ };
+
+ return isActive && (
+ <Scrollbars style={{ maxHeight: `${height}px` }}>
+ <div className={outterClass}>
+
+ <DragDropContext onDragEnd={onDragEnd}>
+ <Droppable
+ droppableId="layerGroup"
+ type="overlayGroups"
+ direction="vertical"
+ >
+ {(provided, snapshot) => (
+ <ul
+ ref={provided.innerRef}
+ // eslint-disable-next-line react/jsx-props-no-spreading
+ {...provided.droppableProps}
+ >
+ {overlayGroups.map(renderLayerList)}
+ {provided.placeholder}
+ </ul>
+ )}
+ </Droppable>
+ </DragDropContext>
+
+ <LayerList
+ title="Base Layers"
+ groupId="baselayers"
+ compareState={compareState}
+ layers={baselayers}
+ layerSplit={layerSplit}
+ />
+ </div>
+ </Scrollbars>
+ );
+}
+
+const mapStateToProps = (state, ownProps) => {
+ const { proj } = state;
+ const activeLayers = getActiveLayers(state);
+ const layerObj = getLayers(activeLayers, { proj: proj.id, group: 'all' });
+ const overlayGroups = getGroupedLayers(layerObj.overlays);
+
+ return {
+ baselayers: layerObj.baselayers,
+ overlayGroups,
+ layerSplit: layerObj.overlays.length,
+ };
+};
+
+export default connect(
+ mapStateToProps,
+ null,
+)(LayersContainer);
+
+LayersContainer.propTypes = {
+ baselayers: PropTypes.array,
+ height: PropTypes.number,
+ isActive: PropTypes.bool,
+ compareState: PropTypes.string,
+ layerSplit: PropTypes.number,
+ overlayGroups: PropTypes.array,
+};
diff --git a/web/js/containers/sidebar/layers.js b/web/js/containers/sidebar/layers.js
deleted file mode 100644
index 5099b0e0b..000000000
--- a/web/js/containers/sidebar/layers.js
+++ /dev/null
@@ -1,106 +0,0 @@
-import React from 'react';
-import { connect } from 'react-redux';
-import { Droppable, DragDropContext } from 'react-beautiful-dnd';
-import PropTypes from 'prop-types';
-import LayerList from './layer-list';
-import { getLayers } from '../../modules/layers/selectors';
-import Scrollbars from '../../components/util/scrollbar';
-
-const getGroupedLayers = (layers) => {
- const allLayerGroups = {};
- layers.forEach((layer) => {
- const { layergroup } = layer;
- if (layergroup && layergroup.length) {
- // TODO just using first group in array for now
- const [groupName] = layergroup;
- if (allLayerGroups[groupName]) {
- allLayerGroups[groupName].push(layer);
- } else {
- allLayerGroups[groupName] = [layer];
- }
- }
- });
- return allLayerGroups;
-};
-
-function Layers (props) {
- const {
- overlays,
- baselayers,
- isActive,
- compareState,
- height,
- layerSplit,
- } = props;
- const outterClass = 'layer-container sidebar-panel';
-
- return isActive && (
- <Scrollbars style={{ maxHeight: `${height}px` }}>
- <div className={outterClass}>
- <DragDropContext onDragEnd={() => { console.log('dropped'); }}>
- <Droppable
- droppableId="layerGroup"
- type="overlayGroups"
- direction="vertical"
- >
- {(provided, snapshot) => (
- <ul
- id=""
- ref={provided.innerRef}
- // eslint-disable-next-line react/jsx-props-no-spreading
- {...provided.droppableProps}
- >
- {Object.keys(overlays).map((groupName) => (
- <LayerList
- key={groupName}
- title={groupName}
- groupId={groupName}
- compareState={compareState}
- layerSplit={layerSplit}
- layers={overlays[groupName]}
- />
- ))}
- {provided.placeholder}
- </ul>
- )}
- </Droppable>
- </DragDropContext>
- <LayerList
- title="Base Layers"
- groupId="baselayers"
- compareState={compareState}
- layers={baselayers}
- layerSplit={layerSplit}
- />
- </div>
- </Scrollbars>
- );
-}
-
-const mapStateToProps = (state, ownProps) => {
- const { layers, proj } = state;
- const { compareState } = ownProps;
- const componentLayers = layers[compareState];
- const layerObj = getLayers(componentLayers, { proj: proj.id, group: 'all' });
- const overlays = getGroupedLayers(layerObj.overlays);
-
- return {
- baselayers: layerObj.baselayers,
- overlays,
- layerSplit: layerObj.overlays.length,
- };
-};
-
-export default connect(
- mapStateToProps,
- null,
-)(Layers);
-
-Layers.propTypes = {
- baselayers: PropTypes.array,
- height: PropTypes.number,
- isActive: PropTypes.bool,
- compareState: PropTypes.string,
- layerSplit: PropTypes.number,
- overlays: PropTypes.object,
-};
diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.js
index 89b3afb63..a29b6e85b 100644
--- a/web/js/containers/sidebar/sidebar.js
+++ b/web/js/containers/sidebar/sidebar.js
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { get as lodashGet } from 'lodash';
import { TabContent, TabPane } from 'reactstrap';
import googleTagManager from 'googleTagManager';
-import Layers from './layers';
+import LayersContainer from './layers-container';
import Events from './events';
import Data from './data';
import CompareCase from './compare';
@@ -15,7 +15,7 @@ import {
loadCustom as loadCustomPalette,
} from '../../modules/palettes/util';
import { loadedCustomPalettes } from '../../modules/palettes/actions';
-import { getLayers } from '../../modules/layers/selectors';
+import { getLayers, getActiveLayers } from '../../modules/layers/selectors';
import ErrorBoundary from '../error-boundary';
import util from '../../util/util';
import {
@@ -147,7 +147,7 @@ class Sidebar extends React.Component {
);
} if (!isCompareMode) {
return (
- <Layers
+ <LayersContainer
height={subComponentHeight - 20}
isActive={activeTab === 'layers'}
compareState={activeString}
@@ -264,7 +264,6 @@ function mapStateToProps(state) {
browser,
sidebar,
compare,
- layers,
config,
modal,
measure,
@@ -276,7 +275,7 @@ function mapStateToProps(state) {
const { isDistractionFreeModeActive } = ui;
const { activeTab, isCollapsed, mobileCollapsed } = sidebar;
const { activeString } = compare;
- const numberOfLayers = getLayers(layers[activeString], {}, state).length;
+ const numberOfLayers = getLayers(getActiveLayers(state), {}, state).length;
const tabTypes = getActiveTabs(config);
const snapshotModalOpen = modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT';
const isMobile = browser.lessThan.medium;
diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.js
index e3a88d684..7706d8402 100644
--- a/web/js/containers/timeline/timeline.js
+++ b/web/js/containers/timeline/timeline.js
@@ -37,6 +37,7 @@ import {
import {
dateRange as getDateRange,
hasSubDaily,
+ getActiveLayers,
} from '../../modules/layers/selectors';
import {
selectDate,
@@ -1402,7 +1403,7 @@ function mapStateToProps(state) {
const isScreenWidthLessThan450 = screenWidth < 450;
// handle active layer filtering and check for subdaily
- const activeLayers = layers[compare.activeString];
+ const activeLayers = getActiveLayers(state);
const projection = proj.id;
const activeLayersFiltered = filterProjLayersWithStartDate(activeLayers, projection);
const hasSubdailyLayers = isCompareModeActive
@@ -1703,7 +1704,7 @@ const getTimelineEndDateLimit = (state) => {
date, layers, compare, proj,
} = state;
const { appNow } = date;
- const activeLayers = layers[compare.activeString];
+ const activeLayers = getActiveLayers(state);
let layerDateRange;
if (compare.active) {
diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.js
index af2fb96a4..5a27015ff 100644
--- a/web/js/containers/toolbar.js
+++ b/web/js/containers/toolbar.js
@@ -29,9 +29,9 @@ import { clearGraticule, refreshGraticule } from '../modules/layers/actions';
import { notificationWarnings } from '../modules/image-download/constants';
import Notify from '../components/image-download/notify';
import { hasCustomPaletteInActiveProjection } from '../modules/palettes/util';
-import { getLayers } from '../modules/layers/selectors';
import Geosearch from '../components/geosearch/geosearch';
import { toggleShowGeosearch, toggleDialogVisible } from '../modules/geosearch/actions';
+import { getLayers, getActiveLayers } from '../modules/layers/selectors';
Promise.config({ cancellation: true });
@@ -339,13 +339,14 @@ class toolbarContainer extends Component {
const mapStateToProps = (state) => {
const {
- animation, browser, notifications, palettes, compare, map, measure, modal, layers, proj, data, ui, geosearch,
+ animation, browser, notifications, palettes, compare, map, measure, modal, proj, data, ui, geosearch,
} = state;
const { isDistractionFreeModeActive } = ui;
const { number, type } = notifications;
const { activeString } = compare;
+ const activeLayers = getActiveLayers(state);
const activeLayersForProj = getLayers(
- layers[activeString],
+ activeLayers,
{ proj: proj.id },
state,
);
@@ -383,7 +384,7 @@ const mapStateToProps = (state) => {
isRotated: Boolean(map.rotation !== 0),
hasGraticule: Boolean(
lodashGet(
- lodashFind(layers[activeString], { id: 'Graticule' }) || {},
+ lodashFind(activeLayers, { id: 'Graticule' }) || {},
'visible',
),
),
diff --git a/web/js/location.js b/web/js/location.js
index 88945411b..8dc893295 100644
--- a/web/js/location.js
+++ b/web/js/location.js
@@ -21,7 +21,7 @@ import {
serializeLayers,
mapLocationToLayerState,
} from './modules/layers/util';
-import { resetLayers, hasSubDaily } from './modules/layers/selectors';
+import { resetLayers, hasSubDaily, getActiveLayers } from './modules/layers/selectors';
import { eventsReducerState } from './modules/natural-events/reducers';
import { mapLocationToPaletteState } from './modules/palettes/util';
import { mapLocationToAnimationState } from './modules/animation/util';
@@ -204,8 +204,7 @@ const getParameters = function(config, parameters) {
let zoom = currentItemState;
// check if subdaily timescale zoom to determine if reset is needed
if (zoom > 3) {
- const { layers, compare } = state;
- const hasSubdailyLayers = hasSubDaily(layers[compare.activeString]);
+ const hasSubdailyLayers = hasSubDaily(getActiveLayers(state));
if (!hasSubdailyLayers) {
zoom = 3; // reset to day
}
@@ -224,8 +223,7 @@ const getParameters = function(config, parameters) {
let interval = currentItemState;
// check if subdaily timescale zoom to determine if reset is needed
if (interval > 3) {
- const { layers, compare } = state;
- const hasSubdailyLayers = hasSubDaily(layers[compare.activeString]);
+ const hasSubdailyLayers = hasSubDaily(getActiveLayers(state));
if (!hasSubdailyLayers) {
interval = 3; // reset to day
}
@@ -262,8 +260,7 @@ const getParameters = function(config, parameters) {
let customInterval = currentItemState;
// check if subdaily customInterval to determine if reset is needed
if (customInterval > 3) {
- const { layers, compare } = state;
- const hasSubdailyLayers = hasSubDaily(layers[compare.activeString]);
+ const hasSubdailyLayers = hasSubDaily(getActiveLayers(state));
if (!hasSubdailyLayers) {
customInterval = 3; // reset to day
}
diff --git a/web/js/map/data/ui.js b/web/js/map/data/ui.js
index f9004f747..c339fc9bb 100644
--- a/web/js/map/data/ui.js
+++ b/web/js/map/data/ui.js
@@ -16,7 +16,7 @@ import { CHANGE_TAB as CHANGE_SIDEBAR_TAB } from '../../modules/sidebar/constant
import { toggleGranule } from '../../modules/data/actions';
import { SELECT_DATE } from '../../modules/date/constants';
import { LOCATION_POP_ACTION } from '../../redux-location-state-customs';
-import { getLayers } from '../../modules/layers/selectors';
+import { getLayers, getActiveLayers } from '../../modules/layers/selectors';
import { getDataProductsFromActiveLayers, doesSelectedExist } from '../../modules/data/selectors';
import * as LAYER_CONSTANTS from '../../modules/layers/constants';
import { CHANGE_PROJECTION } from '../../modules/projection/constants';
@@ -83,11 +83,8 @@ export default function dataUi(store, ui, config) {
};
const updateLayers = function() {
const state = store.getState();
- const {
- layers, compare, proj, data,
- } = state;
- const { activeString } = compare;
- const activeLayers = getLayers(layers[activeString], { proj: proj.id }, state);
+ const { proj, data } = state;
+ const activeLayers = getLayers(getActiveLayers(state), { proj: proj.id }, state);
// If a layer was removed and the product no longer exists,
// remove any selected items in that product
@@ -95,7 +92,8 @@ export default function dataUi(store, ui, config) {
// everything changes to models.
const products = getDataProductsFromActiveLayers(activeLayers, config, proj.id);
lodashEach(data.selectedGranules, (selected) => {
- if (!products[selected.product] && !lodashFind(layers[activeString], { product: selected.product })) {
+ const { product } = selected;
+ if (!products[product] && !lodashFind(getActiveLayers(state), { product })) {
store.dispatch(toggleGranule(selected));
}
});
@@ -103,8 +101,8 @@ export default function dataUi(store, ui, config) {
const query = function() {
const state = store.getState();
const dataState = state.data;
- const { compare, layers, proj } = state;
- const activeLayers = getLayers(layers[compare.activeString], { proj: proj.id });
+ const { proj } = state;
+ const activeLayers = getLayers(getActiveLayers(state), { proj: proj.id });
if (state.sidebar.activeTab !== 'download') {
return;
}
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index b187f0ce0..c1586c331 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -20,6 +20,7 @@ import util from '../util/util';
import lookupFactory from '../ol/lookupimagetile';
import { createVectorUrl, getGeographicResolutionWMS, mergeBreakpointLayerAttributes } from './util';
import { datesinDateRanges, prevDateInDateRange } from '../modules/layers/util';
+import getSelectedDate from '../modules/date/selectors';
import {
isActive as isPaletteActive,
getKey as getPaletteKeys,
@@ -93,7 +94,6 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
*/
self.createLayer = function(def, options) {
const state = store.getState();
- const activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
options = options || {};
const group = options.group || null;
const { closestDate, nextDate, previousDate } = self.getRequestDates(def, options);
@@ -107,7 +107,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
if (!layer) {
// layer is not in the cache
- if (!date) date = options.date || state.date[activeDateStr];
+ if (!date) date = options.date || getSelectedDate(state);
const cacheOptions = getCacheOptions(def.period, date, state);
const attributes = {
id: def.id,
@@ -178,8 +178,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
*/
self.getRequestDates = function(def, options) {
const state = store.getState();
- const activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
- const stateCurrentDate = new Date(state.date[activeDateStr]);
+ const stateCurrentDate = new Date(getSelectedDate(state));
const previousLayer = options.previousLayer || {};
let date = options.date || stateCurrentDate;
let previousDateFromRange;
@@ -320,7 +319,6 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
* @returns {object} OpenLayers WMTS layer
*/
const createLayerWMTS = function(def, options, day, state) {
- const activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
const proj = state.proj.selected;
const source = config.sources[def.source];
if (!source) {
@@ -330,7 +328,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
if (!matrixSet) {
throw new Error(`${def.id}: Undefined matrix set: ${def.matrixSet}`);
}
- let date = options.date || state.date[activeDateStr];
+ let date = options.date || getSelectedDate(state);
if (def.period === 'subdaily' && !date) {
date = self.getRequestDates(def, options).closestDate;
date = new Date(date.getTime());
@@ -382,14 +380,13 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
* @param {object} attributes
*/
const createLayerVector = function(def, options, day, state, attributes) {
- const { proj, compare, animation } = state;
+ const { proj, animation } = state;
let date;
let gridExtent;
let matrixIds;
let start;
let layerExtent;
const selectedProj = proj.selected;
- const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
const source = config.sources[def.source];
const animationIsPlaying = animation.isPlaying;
gridExtent = selectedProj.maxExtent;
@@ -426,7 +423,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
const layerName = def.layer || def.id;
const tileMatrixSet = def.matrixSet;
- date = options.date || state.date[activeDateStr];
+ date = options.date || getSelectedDate(state);
if (day && def.wrapadjacentdays) date = util.dateAdd(date, 'day', day);
const urlParameters = createVectorUrl(date, layerName, tileMatrixSet);
@@ -495,8 +492,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
* @returns {object} OpenLayers WMS layer
*/
const createLayerWMS = function(def, options, day, state) {
- const { proj, compare } = state;
- const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
+ const { proj } = state;
const selectedProj = proj.selected;
let urlParameters;
let date;
@@ -537,7 +533,7 @@ export default function mapLayerBuilder(models, config, cache, ui, store) {
urlParameters = '';
- date = options.date || state.date[activeDateStr];
+ date = options.date || getSelectedDate(state);
if (day && def.wrapadjacentdays) {
date = util.dateAdd(date, 'day', day);
}
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index d4a6ed1a7..bf201ff6d 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -50,9 +50,11 @@ import * as vectorStyleConstants from '../modules/vector-styles/constants';
import { setStyleFunction } from '../modules/vector-styles/selectors';
import {
getLayers,
+ getActiveLayers,
isRenderable as isRenderableLayer,
getMaxZoomLevelLayerCollection,
} from '../modules/layers/selectors';
+import getSelectedDate from '../modules/date/selectors';
import { EXIT_ANIMATION, STOP_ANIMATION } from '../modules/animation/constants';
import {
CLEAR_ROTATE, RENDERED, UPDATE_MAP_UI, FITTED_TO_LEADING_EXTENT, REFRESH_ROTATE,
@@ -170,9 +172,11 @@ export default function mapui(models, config, store, ui) {
const type = 'selection';
const newSelection = action.payload;
const state = store.getState();
- const { compare, layers } = state;
- const activeLayerStr = compare.activeString;
- updateVectorSelection(action.payload, self.selectedVectors, layers[activeLayerStr], type, state);
+ updateVectorSelection(
+ action.payload,
+ self.selectedVectors,
+ getActiveLayers(state), type, state,
+ );
self.selectedVectors = newSelection;
return;
}
@@ -186,9 +190,7 @@ export default function mapui(models, config, store, ui) {
}
};
const onStopAnimation = function() {
- const { compare, layers } = store.getState();
- const activeLayerStr = compare.activeString;
- const hasActiveVectors = hasVectorLayers(layers[activeLayerStr]);
+ const hasActiveVectors = hasVectorLayers(getActiveLayers(store.getState()));
if (hasActiveVectors) {
reloadLayers();
}
@@ -566,21 +568,17 @@ export default function mapui(models, config, store, ui) {
const reloadLayers = self.reloadLayers = function(map) {
map = map || self.selected;
const state = store.getState();
- const { layers, proj } = state;
- const compareState = state.compare;
- const layerGroupStr = compareState.activeString;
- const activeLayers = layers[layerGroupStr];
- if (!config.features.compare || !compareState.active) {
- const compareMapDestroyed = !compareState.active && compareMapUi.active;
+
+ const { layers, proj, compare } = state;
+ if (!config.features.compare || !compare.active) {
+ const compareMapDestroyed = !compare.active && compareMapUi.active;
if (compareMapDestroyed) {
compareMapUi.destroy();
}
clearLayers(map);
const defs = getLayers(
- activeLayers,
- {
- reverse: true,
- },
+ getActiveLayers(state),
+ { reverse: true },
state,
);
lodashEach(defs, (def) => {
@@ -594,16 +592,16 @@ export default function mapui(models, config, store, ui) {
const stateArray = [['active', 'selected'], ['activeB', 'selectedB']];
clearLayers(map);
if (
- compareState
- && !compareState.isCompareA
- && compareState.mode === 'spy'
+ compare
+ && !compare.isCompareA
+ && compare.mode === 'spy'
) {
stateArray.reverse(); // Set Layer order based on active A|B group
}
lodashEach(stateArray, (arr) => {
map.addLayer(getCompareLayerGroup(arr, layers, proj.id, state));
});
- compareMapUi.create(map, compareState.mode);
+ compareMapUi.create(map, compare.mode);
// add active map marker back in compare mode post createLayer
if (self.activeMarker) {
addMarkerAndUpdateStore();
@@ -645,16 +643,14 @@ export default function mapui(models, config, store, ui) {
let renderable;
const layers = self.selected.getLayers();
const layersState = state.layers;
- const activeGroupStr = state.compare.activeString;
- const activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
layers.forEach((layer) => {
const group = layer.get('group');
// Not in A|B
if (layer.wv) {
renderable = isRenderableLayer(
layer.wv.id,
- layersState[activeGroupStr],
- state.date[activeDateStr],
+ getActiveLayers(state),
+ getSelectedDate(state),
state,
);
layer.setVisible(renderable);
@@ -689,12 +685,10 @@ export default function mapui(models, config, store, ui) {
*/
function updateOpacity(action) {
const state = store.getState();
- const { layers, compare } = state;
- const activeStr = compare.isCompareA ? 'active' : 'activeB';
- const def = lodashFind(layers[activeStr], {
+ const def = lodashFind(getActiveLayers(state), {
id: action.id,
});
- const layer = findLayer(def, activeStr);
+ const layer = findLayer(def, state.compare.activeString);
layer.setOpacity(action.opacity);
updateLayerVisibilities();
@@ -712,11 +706,9 @@ export default function mapui(models, config, store, ui) {
function addLayer(def, date, activeLayers) {
const state = store.getState();
- const { compare, layers } = state;
- const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';
- const activeLayerStr = compare.isCompareA ? 'active' : 'activeB';
- date = date || state.date[activeDateStr];
- activeLayers = activeLayers || layers[activeLayerStr];
+ const { compare } = state;
+ date = date || getSelectedDate(state);
+ activeLayers = activeLayers || getActiveLayers(state);
const reverseLayers = lodashCloneDeep(activeLayers).reverse();
const mapIndex = lodashFindIndex(reverseLayers, {
id: def.id,
@@ -726,12 +718,12 @@ export default function mapui(models, config, store, ui) {
if (firstLayer && firstLayer.get('group')) {
// Find which map layer-group is the active LayerGroup
// and add layer to layerGroup in correct location
- const activelayer = firstLayer.get('group') === activeLayerStr
+ const activelayer = firstLayer.get('group') === compare.activeString
? firstLayer
: mapLayers[1];
const newLayer = createLayer(def, {
date,
- group: activeLayerStr,
+ group: compare.activeString,
});
activelayer.getLayers().insertAt(mapIndex, newLayer);
compareMapUi.create(self.selected, compare.mode);
@@ -755,12 +747,11 @@ export default function mapui(models, config, store, ui) {
function removeLayer(action) {
const state = store.getState();
const { compare } = state;
- const activeLayerStr = compare.isCompareA ? 'active' : 'activeB';
const { def } = action;
- const layer = findLayer(def, activeLayerStr);
+ const layer = findLayer(def, compare.activeString);
if (compare && compare.active) {
- const layerGroup = getActiveLayerGroup(self.selected, activeLayerStr);
+ const layerGroup = getActiveLayerGroup(self.selected, compare.activeString);
if (layerGroup) layerGroup.getLayers().remove(layer);
} else {
self.selected.removeLayer(layer);
@@ -781,11 +772,8 @@ export default function mapui(models, config, store, ui) {
const updateDate = self.updateDate = function() {
const state = store.getState();
const { compare } = state;
- const layerState = state.layers;
- const activeLayerStr = compare.activeString;
- const activeDate = compare.isCompareA ? 'selected' : 'selectedB';
const activeLayers = getLayers(
- layerState[activeLayerStr],
+ getActiveLayers(state),
{},
state,
).reverse();
@@ -794,9 +782,9 @@ export default function mapui(models, config, store, ui) {
if (compare && compare.active) {
layerGroups = self.selected.getLayers().getArray();
if (layerGroups.length === 2) {
- layerGroup = layerGroups[0].get('group') === activeLayerStr
+ layerGroup = layerGroups[0].get('group') === compare.activeString
? layerGroups[0]
- : layerGroups[1].get('group') === activeLayerStr
+ : layerGroups[1].get('group') === compare.activeString
? layerGroups[1]
: null;
}
@@ -815,12 +803,12 @@ export default function mapui(models, config, store, ui) {
layerGroup.getLayers().setAt(
index,
createLayer(def, {
- group: activeLayerStr,
- date: state.date[activeDate],
+ group: compare.activeString,
+ date: getSelectedDate(state),
previousLayer: layerValue ? layerValue.wv : null,
}),
);
- compareMapUi.update(activeLayerStr);
+ compareMapUi.update(compare.activeString);
}
} else {
const index = findLayerIndex(def);
@@ -832,9 +820,8 @@ export default function mapui(models, config, store, ui) {
let vectorStyleId;
vectorStyleId = def.vectorStyle.id;
- if (state.layers[activeLayerStr]) {
- const layers = state.layers[activeLayerStr];
- layers.forEach((layer) => {
+ if (getActiveLayers(state)) {
+ getActiveLayers(state).forEach((layer) => {
if (layer.id === layerName && layer.custom) {
vectorStyleId = layer.custom;
}
@@ -872,7 +859,7 @@ export default function mapui(models, config, store, ui) {
*
* @returns {object} Layer object
*/
- function findLayer(def, layerGroupStr) {
+ function findLayer(def, activeCompareState) {
const layers = self.selected.getLayers().getArray();
let layer = lodashFind(layers, {
wv: {
@@ -883,7 +870,7 @@ export default function mapui(models, config, store, ui) {
if (!layer && layers.length && layers[0].get('group')) {
let olGroupLayer;
lodashEach(layers, (layerGroup) => {
- if (layerGroup.get('group') === layerGroupStr) {
+ if (layerGroup.get('group') === activeCompareState) {
olGroupLayer = layerGroup;
}
});
@@ -961,9 +948,7 @@ export default function mapui(models, config, store, ui) {
*/
function createMap(proj, dateSelected) {
const state = store.getState();
- const { date, compare } = state;
- const activeDate = compare.isCompareA ? 'selected' : 'selectedB';
- dateSelected = dateSelected || date[activeDate];
+ dateSelected = dateSelected || getSelectedDate(state);
const id = `wv-map-${proj.id}`;
const $map = $('<div></div>')
.attr('id', id)
diff --git a/web/js/modules/animation/actions.js b/web/js/modules/animation/actions.js
index 7841641ba..4f99eab2f 100644
--- a/web/js/modules/animation/actions.js
+++ b/web/js/modules/animation/actions.js
@@ -13,15 +13,15 @@ import {
} from './constants';
import util from '../../util/util';
import { timeScaleFromNumberKey } from '../date/constants';
+import getSelectedDate from '../date/selectors';
export function onActivate() {
return (dispatch, getState) => {
- const { compare, date, animation } = getState();
+ const { date, animation } = getState();
const {
customSelected, customDelta, delta, customInterval, interval,
} = date;
- const dateStr = compare.isCompareA ? 'selected' : 'selectedB';
- const activeDate = date[dateStr];
+ const activeDate = getSelectedDate(getState());
if (!animation.startDate || !animation.endDate) {
const timeScaleChangeUnit = customSelected
? timeScaleFromNumberKey[customInterval]
diff --git a/web/js/modules/animation/selectors.js b/web/js/modules/animation/selectors.js
index 40ae9c399..91f4b5a64 100644
--- a/web/js/modules/animation/selectors.js
+++ b/web/js/modules/animation/selectors.js
@@ -4,7 +4,7 @@ import {
imageUtilGetCoordsFromPixelValues,
getDownloadUrl,
} from '../image-download/util';
-import { getLayers, hasSubDaily } from '../layers/selectors';
+import { getActiveLayers, getLayers, hasSubDaily } from '../layers/selectors';
import { timeScaleFromNumberKey } from '../date/constants';
/*
* loops through dates and created image
@@ -24,19 +24,18 @@ export default function getImageArray(
state,
) {
const {
- animation, proj, map, date, layers, compare, geosearch,
+ animation, proj, map, date, geosearch,
} = state;
const { startDate, endDate, url } = gifComponentProps;
const { boundaries, showDates } = gifComponentState;
const {
customInterval, interval, customDelta, delta, customSelected,
} = date;
- const { activeString } = compare;
const a = [];
const fromDate = new Date(startDate);
const toDate = new Date(endDate);
- const isSubDaily = hasSubDaily(layers[activeString]);
const markerCoordinates = geosearch.coordinates;
+ const isSubDaily = hasSubDaily(getActiveLayers(state));
let current = fromDate;
let j = 0;
let src;
@@ -54,7 +53,7 @@ export default function getImageArray(
} else {
strDate = util.toISOStringDate(current);
}
- products = getProducts(layers[activeString], current, state);
+ products = getProducts(getActiveLayers(state), current, state);
const lonlats = imageUtilGetCoordsFromPixelValues(boundaries, map.ui.selected);
const dlURL = getDownloadUrl(url, proj, products, lonlats, dimensions, current, false, false, markerCoordinates);
diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.js
index 684ce7ed7..2efe4433b 100644
--- a/web/js/modules/date/util.js
+++ b/web/js/modules/date/util.js
@@ -3,7 +3,7 @@ import update from 'immutability-helper';
import util from '../../util/util';
import { layersParse12 } from '../layers/util';
import {
- dateRange as getDateRange,
+ dateRange as getDateRange, getActiveLayers,
} from '../layers/selectors';
export const filterProjLayersWithStartDate = (layers, projId) => layers.filter((layer) => layer.startDate && layer.projections[projId]);
@@ -72,11 +72,11 @@ export function parsePermalinkDate(defaultDate, str, layerParameters, config) {
*/
export function getMaxActiveLayersDate(state) {
const {
- date, layers, compare, proj,
+ date, proj,
} = state;
const { appNow } = date;
- const activeLayers = layers[compare.activeString];
+ const activeLayers = getActiveLayers(state);
const projection = proj.id;
const activeLayersFiltered = filterProjLayersWithStartDate(activeLayers, projection);
const layersDateRange = getDateRange({}, activeLayersFiltered);
diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.js
index a6e5ca0bc..ba14f54bd 100644
--- a/web/js/modules/layers/actions.js
+++ b/web/js/modules/layers/actions.js
@@ -5,7 +5,9 @@ import {
addLayer as addLayerSelector,
resetLayers as resetLayersSelector,
getLayers as getLayersSelector,
+ getActiveLayers as getActiveLayersSelector,
activateLayersForEventCategory as activateLayersForEventCategorySelector,
+ getActiveLayers,
} from './selectors';
import {
RESET_LAYERS,
@@ -63,17 +65,16 @@ export function addLayer(id, spec = {}) {
const {
layers, compare, proj, config,
} = state;
- const { activeString } = compare;
const layerObj = layers.layerConfig[id];
const activeLayers = getLayersSelector(
- layers[activeString],
+ getActiveLayers(state),
{ group: 'all' },
state,
);
const newLayers = addLayerSelector(
id,
spec,
- layers[activeString],
+ getActiveLayers(state),
layers.layerConfig,
activeLayers.overlays.length || 0,
proj.id,
@@ -83,7 +84,7 @@ export function addLayer(id, spec = {}) {
dispatch({
type: ADD_LAYER,
id,
- activeString,
+ activeString: compare.activeString,
layers: newLayers,
});
};
@@ -124,36 +125,30 @@ export function layerHover(id, isMouseOver) {
export function toggleVisibility(id, visible) {
return (dispatch, getState) => {
- const { layers, compare } = getState();
- const activeString = compare.isCompareA ? 'active' : 'activeB';
- const index = lodashFindIndex(layers[activeString], {
- id,
- });
+ const { compare } = getState();
+ const activeLayers = getActiveLayersSelector(getState());
+ const index = lodashFindIndex(activeLayers, { id });
dispatch({
type: TOGGLE_LAYER_VISIBILITY,
id,
index,
visible,
- activeString,
+ activeString: compare.activeString,
});
};
}
export function removeLayer(id) {
return (dispatch, getState) => {
- const {
- layers, compare, data,
- } = getState();
+ const { compare, data } = getState();
const { activeString } = compare;
- const index = lodashFindIndex(layers[activeString], {
- id,
- });
+ const activeLayers = getActiveLayers(getState());
+ const index = lodashFindIndex(activeLayers, { id });
if (index === -1) {
return console.warn(`Invalid layer ID: ${id}`);
}
-
- const def = layers[activeString][index];
+ const def = activeLayers[index];
if (def.product && def.product === data.selectedProduct) {
dispatch(selectProduct('')); // Clear selected Data product
}
@@ -163,16 +158,16 @@ export function removeLayer(id) {
index,
activeString,
def,
- layers: update(layers[activeString], { $splice: [[index, 1]] }),
+ layers: update(activeLayers, { $splice: [[index, 1]] }),
});
};
}
export function setOpacity(id, opacity) {
return (dispatch, getState) => {
- const { layers, compare } = getState();
- const activeString = compare.isCompareA ? 'active' : 'activeB';
- const index = lodashFindIndex(layers[activeString], {
+ const { compare } = getState();
+ const activeLayers = getActiveLayersSelector(getState());
+ const index = lodashFindIndex(activeLayers, {
id,
});
if (index === -1) {
@@ -184,7 +179,7 @@ export function setOpacity(id, opacity) {
id,
index,
opacity: Number(opacity),
- activeString,
+ activeString: compare.activeString,
});
};
}
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index 5b51a20a4..c33fd217e 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -33,9 +33,9 @@ export const initialState = {
activeB: [],
hoveredLayer: '',
layerConfig: {},
- facetArray: [],
startingLayers: [],
};
+
export function getInitialState(config) {
return lodashAssign({}, initialState, {
active: resetLayers(config.defaults.startingLayers, config.layers),
@@ -45,7 +45,7 @@ export function getInitialState(config) {
}
export function layerReducer(state = initialState, action) {
- const layerGroupStr = action.activeString;
+ const compareState = action.activeString;
switch (action.type) {
case RESET_LAYERS:
case ADD_LAYER:
@@ -53,7 +53,7 @@ export function layerReducer(state = initialState, action) {
case ADD_LAYERS_FOR_EVENT:
case REMOVE_LAYER:
return lodashAssign({}, state, {
- [layerGroupStr]: action.layers,
+ [compareState]: action.layers,
});
case INIT_SECOND_LAYER_GROUP:
return lodashAssign({}, state, {
@@ -65,17 +65,17 @@ export function layerReducer(state = initialState, action) {
});
case TOGGLE_LAYER_VISIBILITY:
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[action.index]: { visible: { $set: action.visible } },
},
});
case SET_THRESHOLD_RANGE_AND_SQUASH:
case SET_DISABLED_CLASSIFICATION: {
- const layerIndex = lodashFindIndex(state[layerGroupStr], {
+ const layerIndex = lodashFindIndex(state[compareState], {
id: action.layerId,
});
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[layerIndex]: {
$merge: action.props,
},
@@ -83,12 +83,12 @@ export function layerReducer(state = initialState, action) {
});
}
case CLEAR_CUSTOM_PALETTE: {
- const layerIndex = lodashFindIndex(state[layerGroupStr], {
+ const layerIndex = lodashFindIndex(state[compareState], {
id: action.layerId,
});
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[layerIndex]: {
custom: {
$set: undefined,
@@ -98,11 +98,11 @@ export function layerReducer(state = initialState, action) {
});
}
case SET_CUSTOM_PALETTE: {
- const layerIndex = lodashFindIndex(state[layerGroupStr], {
+ const layerIndex = lodashFindIndex(state[compareState], {
id: action.layerId,
});
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[layerIndex]: {
custom: {
$set: [action.paletteId],
@@ -112,11 +112,11 @@ export function layerReducer(state = initialState, action) {
});
}
case SET_FILTER_RANGE: {
- const layerIndex = lodashFindIndex(state[layerGroupStr], {
+ const layerIndex = lodashFindIndex(state[compareState], {
id: action.layerId,
});
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[layerIndex]: {
$merge: action.props,
},
@@ -124,12 +124,12 @@ export function layerReducer(state = initialState, action) {
});
}
case CLEAR_VECTORSTYLE: {
- const layerIndex = lodashFindIndex(state[layerGroupStr], {
+ const layerIndex = lodashFindIndex(state[compareState], {
id: action.layerId,
});
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[layerIndex]: {
custom: {
$set: undefined,
@@ -139,11 +139,11 @@ export function layerReducer(state = initialState, action) {
});
}
case SET_VECTORSTYLE: {
- const layerIndex = lodashFindIndex(state[layerGroupStr], {
+ const layerIndex = lodashFindIndex(state[compareState], {
id: action.layerId,
});
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[layerIndex]: {
custom: {
$set: action.vectorStyleId,
@@ -154,7 +154,7 @@ export function layerReducer(state = initialState, action) {
}
case UPDATE_OPACITY:
return update(state, {
- [layerGroupStr]: {
+ [compareState]: {
[action.index]: { opacity: { $set: action.opacity } },
},
});
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.js
index 4db76e06a..90f21be05 100644
--- a/web/js/modules/layers/selectors.js
+++ b/web/js/modules/layers/selectors.js
@@ -12,24 +12,23 @@ import { createSelector } from 'reselect';
import update from 'immutability-helper';
import util from '../../util/util';
import { getLayerNoticesForLayer } from '../notifications/util';
+import getSelectedDate from '../date/selectors';
-// State selectors
-const getLayersState = ({ layers }) => layers;
-const getActiveCompareState = ({ compare }) => (compare.isCompareA ? 'active' : 'activeB');
-const getCurrentDate = ({ date, compare }) => date[compare.isCompareA ? 'selected' : 'selectedB'];
-const getCurrentActiveLayers = ({ compare, layers }) => (compare.isCompareA ? layers.active : layers.activeB);
const getConfigParameters = ({ config }) => (config ? config.parameters : {});
+/**
+ * Return a list of layers for the currently active compare state
+ */
+export const getActiveLayers = ({ compare, layers }) => (compare.isCompareA ? layers.active : layers.activeB);
+
/**
* Return a map of active layers where key is layer id
*/
-export const getActiveLayers = createSelector(
- [getLayersState, getActiveCompareState],
- (layers, activeCompare) => {
+export const getActiveLayersMap = createSelector(
+ [getActiveLayers],
+ (activeLayers) => {
const activeLayerMap = {};
- layers[activeCompare].forEach((layer) => {
- activeLayerMap[layer.id] = layer;
- });
+ activeLayers.forEach((layer) => { activeLayerMap[layer.id] = layer; });
return activeLayerMap;
},
);
@@ -356,7 +355,7 @@ export function available(id, date, layers, parameters) {
* @param {*} id - the layer id
*/
export const memoizedAvailable = createSelector(
- [getCurrentDate, getCurrentActiveLayers, getConfigParameters],
+ [getSelectedDate, getActiveLayers, getConfigParameters],
(currentDate, activeLayers, parameters) => lodashMemoize((id) => available(id, currentDate, activeLayers, parameters)),
);
@@ -370,8 +369,7 @@ export const memoizedAvailable = createSelector(
*/
export function isRenderable(id, activeLayers, date, state) {
const { parameters } = state.config || {};
- const activeDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
- date = date || state.date[activeDateStr];
+ date = date || getSelectedDate(state);
const def = lodashFind(activeLayers, { id });
const notAvailable = !available(id, date, activeLayers, parameters);
@@ -402,9 +400,9 @@ export function isRenderable(id, activeLayers, date, state) {
}
export function activateLayersForEventCategory(activeLayers, state) {
- const { layers, compare } = state;
+ const { layerConfig } = state.layers;
// Turn off all layers in list first
- let newLayers = layers[compare.activeString];
+ let newLayers = getActiveLayers(state);
lodashEach(newLayers, (layer, index) => {
newLayers = update(newLayers, {
[index]: { visible: { $set: false } },
@@ -424,7 +422,7 @@ export function activateLayersForEventCategory(activeLayers, state) {
id,
{ visible },
newLayers,
- layers.layerConfig,
+ layerConfig,
getLayers(newLayers, { group: 'all' }, state).overlays.length,
);
}
@@ -493,7 +491,7 @@ export function getZotsForActiveLayers(state) {
const { sources } = config;
const projection = proj.selected.id;
const zoom = map.ui.selected.getView().getZoom();
- lodashEach(getActiveLayers(state), (layer) => {
+ lodashEach(getActiveLayersMap(state), (layer) => {
if (layer.projections[projection]) {
const overZoomValue = getZoomLevel(layer, zoom, projection, sources);
const layerNotices = getLayerNoticesForLayer(layer.id, notifications);
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index fe4549910..853fee773 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -245,6 +245,7 @@ export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, stat
export const applyStyle = (def, olVectorLayer, state, options) => {
const { config, layers, compare } = state;
const activeGroupStr = options.group ? options.group : compare.activeString;
+ // TODO may not be able to rely on getActiveLayers() here
const activeLayers = layers[activeGroupStr];
const layerName = def.layer || def.id;
if (config.vectorStyles && def.vectorStyle && def.vectorStyle.id) {