Interactive interface for browsing global, full-resolution satellite imagery
disable groups when arriving via old permalinks without lg param
Jason Kentfe8f3e01b137
diff --git a/web/js/location.js b/web/js/location.jsindex 65f80d023..21e35658e 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -19,6 +19,7 @@ import {import {layersParse12,serializeLayers,+ serializeGroupOverlays,mapLocationToLayerState,} from './modules/layers/util';import { resetLayers, hasSubDaily, getActiveLayers } from './modules/layers/selectors';@@ -126,6 +127,7 @@ const getParameters = function(config, parameters) {const now = config.pageLoadTime;const nowMinusSevenDays = util.dateAdd(config.pageLoadTime, 'day', -7);const { initialDate } = config;+ const startingLayers = resetLayers(config.defaults.startingLayers, config.layers);return {p: {stateKey: 'proj.id',@@ -324,7 +326,7 @@ const getParameters = function(config, parameters) {},l: {stateKey: 'layers.active.layers',- initialState: resetLayers(config.defaults.startingLayers, config.layers),+ initialState: startingLayers,type: 'array',options: {parse: (permalink) => layersParse12(permalink, config),@@ -346,10 +348,7 @@ const getParameters = function(config, parameters) {options: {setAsEmptyItem: true,serializeNeedsGlobalState: true,- serialize: (currentItemState, state) => {- const showGroups = get(state, 'layers.active.groupOverlays');- return !showGroups ? currentItemState : undefined;- },+ serialize: (currentItemState, state) => serializeGroupOverlays(currentItemState, state, 'active'),},},l1: {@@ -359,10 +358,10 @@ const getParameters = function(config, parameters) {options: {parse: (permalink) => layersParse12(permalink, config),serializeNeedsGlobalState: true,- serialize: (currentLayers, state) => {+ serialize: (currentBLayers, state) => {const compareIsActive = get(state, 'compare.active');return compareIsActive- ? serializeLayers(currentLayers, state, 'activeB')+ ? serializeLayers(currentBLayers, state, 'activeB'): undefined;},},@@ -375,8 +374,10 @@ const getParameters = function(config, parameters) {setAsEmptyItem: true,serializeNeedsGlobalState: true,serialize: (currentItemState, state) => {- const showGroups = get(state, 'layers.activeB.groupOverlays');- return !showGroups ? currentItemState : undefined;+ const compareIsActive = get(state, 'compare.active');+ return compareIsActive+ ? serializeGroupOverlays(currentItemState, state, 'activeB')+ : undefined;},},},diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex 0725eddc1..e76ff9a05 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -9,6 +9,7 @@ import {isNaN as lodashIsNaN,startCase as lodashStartCase,isArray,+ isEqual as lodashIsEqual,} from 'lodash';import moment from 'moment';import googleTagManager from 'googleTagManager';@@ -827,6 +828,30 @@ export function serializeLayers(layers, state, groupName) {});}+export function serializeGroupOverlays (currentItemState, state, activeString) {+ const { config, parameters } = state;+ const startingLayers = resetLayers(config.defaults.startingLayers, config.layers);+ const layersOnState = lodashGet(state, `layers.${activeString}.layers`);+ const showGroups = lodashGet(state, `layers.${activeString}.groupOverlays`);+ const layersParam = activeString === 'active' ? parameters.l : parameters.l1;+ const layerGroupParam = activeString === 'active' ? parameters.lg : parameters.lg1;+ const layersChanged = !lodashIsEqual(layersOnState, startingLayers);++ // Old permalink => disable groups+ if (!!layersParam && !layerGroupParam) {+ return false;+ }+ // If any change is made to layers, include group param+ if (layersChanged) {+ return showGroups;+ }+ // If app was loaded without layer parameters, only include param if grouping disabled+ if (layersParam === undefined && layerGroupParam === undefined) {+ return !showGroups ? currentItemState : undefined;+ }+ return showGroups;+}+export function toggleVisibility(id, layers) {const index = lodashFindIndex(layers, {id,@@ -1191,6 +1216,7 @@ export function mapLocationToLayerState(},});}+// legacy layers permalinkif (parameters.products && !parameters.l) {const layers = layersParse11(parameters.products, config);@@ -1205,15 +1231,14 @@ export function mapLocationToLayerState(},});}- // Layers are grouped- // TODO need to set layer order as well based on the groups?+ // If permallink without grou paramif (parameters.l && parameters.lg === undefined) {newStateFromLocation = update(newStateFromLocation, {layers: {active: {- groupOverlays: { $set: active.groupOverlays },- overlayGroups: { $set: getOverlayGroups(active.layers) },+ groupOverlays: { $set: false },+ overlayGroups: { $set: [] },layers: { $set: active.layers },},},@@ -1223,8 +1248,8 @@ export function mapLocationToLayerState(newStateFromLocation = update(newStateFromLocation, {layers: {activeB: {- groupOverlays: { $set: activeB.groupOverlays },- overlayGroups: { $set: getOverlayGroups(activeB.layers) },+ groupOverlays: { $set: false },+ overlayGroups: { $set: [] },layers: { $set: activeB.layers },},},