Interactive interface for browsing global, full-resolution satellite imagery
Implement layer-list drag-n-drop #1623
Benjamin King525188354c87
diff --git a/web/js/components/sidebar/products/layer-list.js b/web/js/components/sidebar/products/layer-list.jsindex be69fd245..9c5f89232 100644--- a/web/js/components/sidebar/products/layer-list.js+++ b/web/js/components/sidebar/products/layer-list.js@@ -57,8 +57,14 @@ class LayerList extends React.Component {* @param {Object} result | Result of layer drag*/onDragEnd(replaceSubGroup, result) {- const { layerGroupName, groupId, reorderLayers } = this.props;- const { layers } = this.state;+ const {+ layerGroupName,+ groupId,+ reorderLayers,+ layerSplit,+ activeLayers,+ layers+ } = this.props;if (!result.destination) {return;}@@ -79,9 +85,14 @@ class LayerList extends React.Component {if (nextIndex < newLayerArray.length) {nextLayerId = newLayerArray[nextIndex].id;}- reorderLayers(- replaceSubGroup(layerId, nextLayerId, layerGroupName, groupId)+ const newLayers = replaceSubGroup(+ layerId,+ nextLayerId,+ activeLayers,+ groupId,+ layerSplit);+ reorderLayers(newLayers);}render() {const {@@ -152,12 +163,15 @@ function mapStateToProps(state, ownProps) {groupId,title,layerGroupName,- checkerBoardPattern+ checkerBoardPattern,+ layerSplit} = ownProps;+ const { proj } = state;const { runningLayers } = state.layers;- const { id } = state.proj;+ const { id } = proj;const zoom = state.legacy.map.getZoom();const zots = getZotsForActiveLayers(layers, zoom) || {};+ const activeLayers = state.layers[layerGroupName];return {zots,@@ -165,9 +179,11 @@ function mapStateToProps(state, ownProps) {groupId,title,layerGroupName,+ activeLayers,runningLayers,projId: id,checkerBoardPattern,+ layerSplit,getNames: (layerId, proj) => {return getTitles(state.config, layerId, proj, state);},diff --git a/web/js/components/sidebar/products/products.js b/web/js/components/sidebar/products/products.jsindex 792059470..c8fece926 100644--- a/web/js/components/sidebar/products/products.js+++ b/web/js/components/sidebar/products/products.js@@ -13,7 +13,8 @@ class Products extends React.Component {isActive,layerGroupName,height,- checkerBoardPattern+ checkerBoardPattern,+ layerSplit} = this.props;const outterClass = 'layer-container sidebar-panel';return (@@ -26,6 +27,7 @@ class Products extends React.Component {title="Overlays"groupId="overlays"layerGroupName={layerGroupName}+ layerSplit={layerSplit}layers={baselayers}checkerBoardPattern={checkerBoardPattern}/>@@ -34,6 +36,7 @@ class Products extends React.Component {groupId="baselayers"layerGroupName={layerGroupName}layers={overlays}+ layerSplit={layerSplit}checkerBoardPattern={checkerBoardPattern}/></div>@@ -53,6 +56,7 @@ function mapStateToProps(state, ownProps) {return {baselayers: layerObj.baselayers,overlays: layerObj.overlays,+ layerSplit: layerObj.overlays.length,layerGroupName,height,isActive,diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.jsindex bb9a007e9..3f0052a2f 100644--- a/web/js/modules/layers/reducers.js+++ b/web/js/modules/layers/reducers.js@@ -22,7 +22,6 @@ export const initialState = {startingLayers: []};export function getInitialState(config) {- console.log(resetLayers(config.defaults.startingLayers, config.layers));return lodashAssign({}, initialState, {active: resetLayers(config.defaults.startingLayers, config.layers),layerConfig: config.layers,@@ -48,7 +47,6 @@ export function layerReducer(state = initialState, action) {}case ADD_LAYER:- console.log('add layer');return lodashAssign({}, state, {[layerGroupStr]: addLayer(action.id,diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.jsindex fff8649ba..985495e80 100644--- a/web/js/modules/layers/selectors.js+++ b/web/js/modules/layers/selectors.js@@ -7,7 +7,8 @@ import {isUndefined as lodashIsUndefined,values as lodashValues,sortBy as lodashSortBy,- indexOf as lodashIndexOf+ indexOf as lodashIndexOf,+ findIndex as lodashFindIndex} from 'lodash';import util from '../../util/util';@@ -222,11 +223,17 @@ export function available(id, date, layers, config) {}return true;}-export function replaceSubGroup(layerId, nextLayerId, layers, subGroup) {+export function replaceSubGroup(+ layerId,+ nextLayerId,+ layers,+ subGroup,+ layerSplit+) {if (nextLayerId) {return moveBefore(layerId, nextLayerId, layers);} else {- return pushToBottom(layerId, layers);+ return pushToBottom(layerId, layers, layerSplit);}}function dateRange(spec, activeLayers, config) {@@ -310,45 +317,43 @@ function dateRange(spec, activeLayers, config) {};}}-function pushToBottom(id, activeLayersString) {- // activeLayersString = activeLayersString || self.activeLayers;- // var oldIndex = lodashFindIndex(self[activeLayersString], {- // id: id- // });- // if (oldIndex < 0) {- // throw new Error('Layer is not active: ' + id);- // }- // var def = self[activeLayersString][oldIndex];- // self[activeLayersString].splice(oldIndex, 1);- // if (def.group === 'baselayers') {- // self[activeLayersString].push(def);- // } else {- // self[activeLayersString].splice(split[activeLayersString] - 1, 0, def);- // }+function pushToBottom(id, layers, layerSplit) {+ var oldIndex = lodashFindIndex(layers, {+ id: id+ });+ if (oldIndex < 0) {+ throw new Error('Layer is not active: ' + id);+ }+ var def = layers[oldIndex];+ layers.splice(oldIndex, 1);+ if (def.group === 'baselayers') {+ layers.push(def);+ } else {+ layers.splice(layerSplit - 1, 0, def);+ }+ return layers;}-function moveBefore(sourceId, targetId, activeLayersString) {- // activeLayersString = activeLayersString || self.activeLayers;- // var sourceIndex = lodashFindIndex(self[activeLayersString], {- // id: sourceId- // });- // if (sourceIndex < 0) {- // throw new Error('Layer is not active: ' + sourceId);- // }- // var sourceDef = self[activeLayersString][sourceIndex];- // var targetIndex = lodashFindIndex(self[activeLayersString], {- // id: targetId- // });- // if (targetIndex < 0) {- // throw new Error('Layer is not active: ' + targetId);- // }- // self[activeLayersString].splice(targetIndex, 0, sourceDef);- // if (sourceIndex > targetIndex) {- // sourceIndex++;- // }- // self[activeLayersString].splice(sourceIndex, 1);- // self.events.trigger('update', sourceDef, targetIndex);- // self.events.trigger('change');+function moveBefore(sourceId, targetId, layers) {+ var sourceIndex = lodashFindIndex(layers, {+ id: sourceId+ });+ if (sourceIndex < 0) {+ throw new Error('Layer is not active: ' + sourceId);+ }+ var sourceDef = layers[sourceIndex];+ var targetIndex = lodashFindIndex(layers, {+ id: targetId+ });+ if (targetIndex < 0) {+ throw new Error('Layer is not active: ' + targetId);+ }+ layers.splice(targetIndex, 0, sourceDef);+ if (sourceIndex > targetIndex) {+ sourceIndex++;+ }+ layers.splice(sourceIndex, 1);+ return layers;}export function getZotsForActiveLayers(config, models, ui) {// var zotObj = {};