Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

toggle grouping

Jason Kentef2e075721ea
diff --git a/web/css/sidebar.css b/web/css/sidebar.css
index 122bb9721..22ee7be6f 100644
--- a/web/css/sidebar.css
+++ b/web/css/sidebar.css
@@ -4,7 +4,7 @@
user-select: none;
}
}
-#productsHolder {
+.products-holder-case {
position: absolute;
z-index: 2;
min-width: 286px;
@@ -19,29 +19,33 @@
border-top: none;
transition: max-height 0.1s ease;
overflow: hidden;
+ .layer-container {
+ box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ -o-box-sizing: border-box;
+ position: relative;
+ border: 1px solid transparent;
+ }
+ .scrollbar-visible .sidebar-panel {
+ padding-right: 10px;
+ }
+ .main-nav {
+ background: rgba(40, 40, 40, 0.85);
+ border-right: 1px solid #333;
+ border-left: 1px solid #333;
+ }
+ > .tab-content {
+ background: rgba(40, 40, 40, 0.85);
+ border: 1px solid #333;
+ border-bottom-left-radius: 5px;
+ border-bottom-right-radius: 5px;
+ }
+ .react-switch {
+ margin: 5px 0 0 10px;
+ }
}
-#productsHolder .layer-container {
- box-sizing: border-box;
- -moz-box-sizing: border-box;
- -webkit-box-sizing: border-box;
- -o-box-sizing: border-box;
- position: relative;
- border: 1px solid transparent;
-}
-#productsHolder .scrollbar-visible .sidebar-panel {
- padding-right: 10px;
-}
-#productsHolder .main-nav {
- background: rgba(40, 40, 40, 0.85);
- border-right: 1px solid #333;
- border-left: 1px solid #333;
-}
-#productsHolder > .tab-content {
- background: rgba(40, 40, 40, 0.85);
- border: 1px solid #333;
- border-bottom-left-radius: 5px;
- border-bottom-right-radius: 5px;
-}
+
#wv-logo {
background: url('../brand/images/wv-logo.svg?v=@BUILD_NONCE@') no-repeat center rgba(40, 40, 40, 0.85);
display: block;
diff --git a/web/css/switch.css b/web/css/switch.css
index 4d7950db6..bd14709f3 100644
--- a/web/css/switch.css
+++ b/web/css/switch.css
@@ -21,11 +21,10 @@
display: flex;
}
.react-switch-case {
- width: 20%;
+ width: 40px;
align-items: flex-start;
}
.react-switch-label-case {
- width: 80%;
svg.svg-inline--fa {
margin-left: 5px;
}
@@ -78,4 +77,5 @@
.switch-label-text {
cursor: pointer;
+ color: #fff;
}
diff --git a/web/js/containers/sidebar/layers-container.js b/web/js/containers/sidebar/layers-container.js
index bc7095776..c37a4a11e 100644
--- a/web/js/containers/sidebar/layers-container.js
+++ b/web/js/containers/sidebar/layers-container.js
@@ -5,20 +5,44 @@ import { Draggable, Droppable, DragDropContext } from 'react-beautiful-dnd';
import PropTypes from 'prop-types';
import LayerList from './layer-list';
import { getLayers, getActiveLayers, getGroupedOverlays } from '../../modules/layers/selectors';
-import { reorderLayerGroups as reorderLayerGroupsAction } from '../../modules/layers/actions';
+import {
+ reorderLayerGroups as reorderLayerGroupsAction,
+ toggleLayerGroups as toggleLayerGroupsAction,
+} from '../../modules/layers/actions';
import Scrollbars from '../../components/util/scrollbar';
+import Switch from '../../components/util/switch';
function LayersContainer (props) {
const {
overlayGroups,
+ overlays,
baselayers,
+ showGroups,
isActive,
compareState,
height,
layerSplit,
reorderLayerGroups,
+ toggleLayerGroups,
} = props;
- const outterClass = 'layer-container sidebar-panel';
+
+ /**
+ * Update layer group order after drag/drop
+ * @param {*} result
+ */
+ const onDragEnd = (result) => {
+ const { destination, source } = result;
+ if (!destination || source.index === destination.index) {
+ return;
+ }
+ const newList = Array.from(overlayGroups);
+ const [removed] = newList.splice(source.index, 1);
+ newList.splice(destination.index, 0, removed);
+ const newLayers = newList.flatMap((group) => group.layers).concat(baselayers);
+ const newGroups = newList.map((g) => g.groupName);
+
+ reorderLayerGroups(newLayers, newGroups);
+ };
const renderLayerList = (group, idx) => {
const { groupName, layers } = group;
@@ -48,67 +72,72 @@ function LayersContainer (props) {
));
};
- /**
- * Update layer group order after drag/drop
- * @param {*} result
- */
- const onDragEnd = (result) => {
- const { destination, source } = result;
- if (!destination || source.index === destination.index) {
- return;
- }
- const newList = Array.from(overlayGroups);
- const [removed] = newList.splice(source.index, 1);
- newList.splice(destination.index, 0, removed);
- const newLayers = newList.flatMap((group) => group.layers).concat(baselayers);
- const newGroups = newList.map((g) => g.groupName);
-
- reorderLayerGroups(newLayers, newGroups);
- };
+ const renderLayerGroups = () => (
+ <DragDropContext onDragEnd={onDragEnd}>
+ <Droppable
+ droppableId="layerGroup"
+ type="overlayGroups"
+ direction="vertical"
+ >
+ {(provided, snapshot) => (
+ <ul
+ ref={provided.innerRef}
+ {...provided.droppableProps}
+ >
+ {overlayGroups.map(renderLayerList)}
+ {provided.placeholder}
+ </ul>
+ )}
+ </Droppable>
+ </DragDropContext>
+ );
return isActive && (
- <Scrollbars style={{ maxHeight: `${height}px` }}>
- <div className={outterClass}>
+ <>
+ <Switch
+ id="layer-group-toggle"
+ label="Toggle Groups"
+ active={showGroups}
+ toggle={toggleLayerGroups}
+ />
+ <Scrollbars style={{ maxHeight: `${height}px` }}>
+ <div className="layer-container sidebar-panel">
- <DragDropContext onDragEnd={onDragEnd}>
- <Droppable
- droppableId="layerGroup"
- type="overlayGroups"
- direction="vertical"
- >
- {(provided, snapshot) => (
- <ul
- ref={provided.innerRef}
- {...provided.droppableProps}
- >
- {overlayGroups.map(renderLayerList)}
- {provided.placeholder}
- </ul>
- )}
- </Droppable>
- </DragDropContext>
+ {showGroups ? renderLayerGroups() : (
+ <LayerList
+ title="Overlays"
+ groupId="overlays"
+ compareState={compareState}
+ layers={overlays}
+ layerSplit={layerSplit}
+ />
+ )}
- <LayerList
- title="Base Layers"
- groupId="baselayers"
- compareState={compareState}
- layers={baselayers}
- layerSplit={layerSplit}
- />
- </div>
- </Scrollbars>
+ <LayerList
+ title="Base Layers"
+ groupId="baselayers"
+ compareState={compareState}
+ layers={baselayers}
+ layerSplit={layerSplit}
+ />
+ </div>
+ </Scrollbars>
+ </>
);
}
const mapStateToProps = (state, ownProps) => {
- const { proj } = state;
+ const { proj, layers } = state;
+ const { showGroups } = layers;
const activeLayers = getActiveLayers(state);
const layerObj = getLayers(activeLayers, { proj: proj.id, group: 'all' });
- const overlayGroups = getGroupedOverlays(state);
+ const overlayGroups = showGroups ? getGroupedOverlays(state) : [];
return {
baselayers: layerObj.baselayers,
+ overlays: layerObj.overlays,
overlayGroups,
+ showGroups,
layerSplit: layerObj.overlays.length,
};
};
@@ -117,6 +146,9 @@ const mapDispatchToProps = (dispatch) => ({
reorderLayerGroups: (layers, groups) => {
dispatch(reorderLayerGroupsAction(layers, groups));
},
+ toggleLayerGroups: () => {
+ dispatch(toggleLayerGroupsAction());
+ },
});
export default connect(
@@ -131,5 +163,8 @@ LayersContainer.propTypes = {
compareState: PropTypes.string,
layerSplit: PropTypes.number,
overlayGroups: PropTypes.array,
+ overlays: PropTypes.array,
reorderLayerGroups: PropTypes.func,
+ showGroups: PropTypes.bool,
+ toggleLayerGroups: PropTypes.func,
};
diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.js
index 76bd4f187..0b7fc5e56 100644
--- a/web/js/modules/layers/actions.js
+++ b/web/js/modules/layers/actions.js
@@ -16,6 +16,7 @@ import {
REORDER_LAYER_GROUPS,
ON_LAYER_HOVER,
TOGGLE_LAYER_VISIBILITY,
+ TOGGLE_LAYER_GROUPS,
REMOVE_LAYER,
UPDATE_OPACITY,
ADD_LAYERS_FOR_EVENT,
@@ -59,6 +60,12 @@ export function activateLayersForEventCategory(activeLayers) {
};
}
+export function toggleLayerGroups() {
+ return {
+ type: TOGGLE_LAYER_GROUPS,
+ };
+}
+
export function addLayer(id, spec = {}) {
googleTagManager.pushEvent({
event: 'layer_added',
diff --git a/web/js/modules/layers/constants.js b/web/js/modules/layers/constants.js
index 07ce712b6..f7f280a6a 100644
--- a/web/js/modules/layers/constants.js
+++ b/web/js/modules/layers/constants.js
@@ -2,6 +2,7 @@ export const RESET_LAYERS = 'LAYERS/RESET_LAYERS_IN_LAYER_GROUP';
export const ADD_LAYER = 'LAYERS/ADD_LAYER_TO_LAYER_GROUP';
export const REORDER_LAYERS = 'LAYERS/REORDER_LAYERS';
export const REORDER_LAYER_GROUPS = 'LAYERS/REORDER_LAYERS_GROUPS';
+export const TOGGLE_LAYER_GROUPS = 'LAYERS/TOGGLE_LAYER_GROUPS';
export const INIT_SECOND_LAYER_GROUP = 'LAYERS/INIT_SECOND_LAYER_GROUP_FOR_AB';
export const TOGGLE_ACTIVE_STATE = 'LAYERS/TOGGLE_ACTIVE_LAYER_STATE';
export const ON_LAYER_HOVER = 'LAYERS/ON_LAYER_HOVER';
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index 6d806624f..30be6d5f3 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -10,6 +10,7 @@ import {
REORDER_LAYERS,
ON_LAYER_HOVER,
TOGGLE_LAYER_VISIBILITY,
+ TOGGLE_LAYER_GROUPS,
REMOVE_LAYER,
UPDATE_OPACITY,
ADD_LAYERS_FOR_EVENT,
@@ -83,6 +84,12 @@ export function layerReducer(state = initialState, action) {
},
});
+ case TOGGLE_LAYER_GROUPS:
+ return {
+ ...state,
+ showGroups: !state.showGroups,
+ };
+
case INIT_SECOND_LAYER_GROUP:
return {
...state,