Interactive interface for browsing global, full-resolution satellite imagery
Move map state out of legacy object
Benjamin Kingf29f2a247cd0
diff --git a/web/js/containers/animation-widget.js b/web/js/containers/animation-widget.jsindex b04d49f08..b65270633 100644--- a/web/js/containers/animation-widget.js+++ b/web/js/containers/animation-widget.js@@ -300,7 +300,7 @@ function mapStateToProps(state) {modal,palettes,config,- legacy+ map} = state;const {startDate,@@ -325,7 +325,7 @@ function mapStateToProps(state) {maxDate: layersLastDateTime(layers[activeStr], config),isActive:isActive &&- lodashGet(legacy, 'map.ui.selected.frameState_') &&+ lodashGet(map, 'ui.selected.frameState_') &&sidebar.activeTab !== 'download' && // No Animation when data download is active!(modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT'), // No Animation when Image download is openhasSubdailyLayers,@@ -343,7 +343,7 @@ function mapStateToProps(state) {? timeScaleFromNumberKey[customInterval]: timeScaleFromNumberKey[interval],hasCustomPalettes,- map: legacy.map,+ map,promiseImageryForTime: (date, layers) => {return promiseImageryForTime(date, layers, state);},diff --git a/web/js/containers/gif.js b/web/js/containers/gif.jsindex 0c28ee4e7..bcbe7e2a1 100644--- a/web/js/containers/gif.js+++ b/web/js/containers/gif.js@@ -308,7 +308,7 @@ class GIF extends Component {}function mapStateToProps(state, ownProps) {- const { browser, proj, legacy, animation, date, config } = state;+ const { browser, proj, animation, map, date, config } = state;const { speed, startDate, endDate } = animation;const { screenWidth, screenHeight } = browser;const { customSelected, interval, customInterval, customDelta } = date;@@ -329,7 +329,7 @@ function mapStateToProps(state, ownProps) {endDate: endDate.toISOString(),increment: `${increment} Between Frames`,speed,- map: legacy.map,+ map,url,getImageArray: (gifComponentProps, gifComponentState, dimensions) => {return getImageArray(diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.jsindex 2ae164d8e..2c4867d7a 100644--- a/web/js/containers/image-download.js+++ b/web/js/containers/image-download.js@@ -127,9 +127,8 @@ class ImageDownloadContainer extends Component {}function mapStateToProps(state) {- const { config, proj, browser, layers, compare, date } = state;+ const { config, proj, browser, layers, compare, date, map } = state;const { screenWidth, screenHeight } = browser;- const { map } = state.legacy;const activeDateStr = compare.isCompareA ? 'selected' : 'selectedB';let url = DEFAULT_URL;if (config.features.imageDownload && config.features.imageDownload.url) {diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.jsindex 45c71c5a7..c4a426a5a 100644--- a/web/js/containers/sidebar/events.js+++ b/web/js/containers/sidebar/events.js@@ -155,8 +155,9 @@ function mapStateToProps(state) {let visibleEvents = {};const events = lodashGet(requestedEvents, 'response');const sources = lodashGet(requestedEventSources, 'response');- if (events && state.legacy.map.extent) {- let extent = showAll ? proj.selected.maxExtent : state.legacy.map.extent;+ const mapExtent = lodashGet(state, 'map.extent');+ if (events && mapExtent) {+ let extent = showAll ? proj.selected.maxExtent : mapExtent;visibleEvents = getEventsWithinExtent(events,selected,diff --git a/web/js/containers/sidebar/layer-list.js b/web/js/containers/sidebar/layer-list.jsindex eb3bab3aa..c90423542 100644--- a/web/js/containers/sidebar/layer-list.js+++ b/web/js/containers/sidebar/layer-list.js@@ -10,6 +10,7 @@ import {available} from '../../modules/layers/selectors';import { reorderLayers } from '../../modules/layers/actions';+import { get as lodashGet } from 'lodash';const reorder = (list, startIndex, endIndex) => {const result = Array.from(list);@@ -175,13 +176,13 @@ function mapStateToProps(state, ownProps) {checkerBoardPattern,layerSplit} = ownProps;- const { proj, compare, config, legacy } = state;+ const { proj, compare, config, map } = state;const { runningLayers } = state.layers;const { id } = proj;const activeDateString = compare.isCompareA ? 'selected' : 'selectedB';const activeLayers = state.layers[layerGroupName];- const zots = legacy.map.ui- ? getZotsForActiveLayers(config, proj, legacy.map, activeLayers)+ const zots = lodashGet(map, 'ui.selected')+ ? getZotsForActiveLayers(config, proj, map, activeLayers): {};return {zots,diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.jsindex 6e127885c..52de109fb 100644--- a/web/js/containers/sidebar/sidebar.js+++ b/web/js/containers/sidebar/sidebar.js@@ -65,7 +65,7 @@ class Sidebar extends React.Component {updateDimensions() {const { subComponentHeight } = this.state;const { isMobile, screenHeight } = this.props;- if (!isMobile) {+ if (!isMobile && this.iconElement) {let newHeight;let iconHeight = this.iconElement.clientHeight;let topOffset = Math.abs(this.iconElement.getBoundingClientRect().top);diff --git a/web/js/containers/timeline/timeline.js b/web/js/containers/timeline/timeline.jsindex 27dd6d3cf..6ec8e890a 100644--- a/web/js/containers/timeline/timeline.js+++ b/web/js/containers/timeline/timeline.js@@ -358,7 +358,7 @@ function mapStateToProps(state) {const {config,compare,- legacy,+ map,layers,browser,date,@@ -455,7 +455,7 @@ function mapStateToProps(state) {hideTimeline:(modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT') || animation.gifActive,animationDisabled:- !lodashGet(legacy, 'map.ui.selected.frameState_') ||+ !lodashGet(map, 'ui.selected.frameState_') ||sidebar.activeTab === 'download'};}diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.jsindex 547757c8b..913b2fb39 100644--- a/web/js/containers/toolbar.js+++ b/web/js/containers/toolbar.js@@ -165,7 +165,7 @@ function mapStateToProps(state) {notificationType: type,notificationContentNumber: number,config: state.config,- isImageDownloadActive: Boolean(lodashGet(state, 'legacy.map.ui.selected'))+ isImageDownloadActive: Boolean(lodashGet(state, 'map.ui.selected'))};}const mapDispatchToProps = dispatch => ({diff --git a/web/js/location.js b/web/js/location.jsindex 542a37247..fc051a61e 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -15,10 +15,7 @@ import {} from './modules/layers/util';import { resetLayers, hasSubDaily } from './modules/layers/selectors';import { eventsReducerState } from './modules/natural-events/reducers';-import {- mapLocationToPaletteState,- preloadPalettes-} from './modules/palettes/util';+import { mapLocationToPaletteState } from './modules/palettes/util';import { mapLocationToAnimationState } from './modules/animation/util';import { mapLocationToSidebarState } from './modules/sidebar/util';import util from './util/util';diff --git a/web/js/map/rotation.js b/web/js/map/rotation.jsindex eeaaf8817..1b1a46649 100644--- a/web/js/map/rotation.js+++ b/web/js/map/rotation.js@@ -76,7 +76,7 @@ export function MapRotate(ui, models, store) {* @returns {void}*/this.setRotationEvents = function(map, id) {- const legacyState = store.getState().legacy;+ const mapState = store.getState().map;var dur = 500;var $leftButton = $('#wv-map-' + id + ' .wv-map-rotate-left');var $rightButton = $('#wv-map-' + id + ' .wv-map-rotate-right');@@ -125,7 +125,7 @@ export function MapRotate(ui, models, store) {$resetButton.button({- label: Number(legacyState.map.rotation * (180 / Math.PI)).toFixed()+ label: Number(mapState.rotation * (180 / Math.PI)).toFixed()}).mousedown(function() {// reset rotationdiff --git a/web/js/map/ui.js b/web/js/map/ui.jsindex fa2fb5146..e46fcbae2 100644--- a/web/js/map/ui.js+++ b/web/js/map/ui.js@@ -92,9 +92,9 @@ export function mapui(models, config, store, ui) {return addLayer(def);case LOCATION_POP_ACTION:const newState = util.fromQueryString(action.payload.search);- const extent = lodashGet(action, 'payload.query.legacy.map.extent');+ const extent = lodashGet(action, 'payload.query.map.extent');const rotation =- lodashGet(action, 'payload.query.legacy.map.rotation') || 0;+ lodashGet(action, 'payload.query.map.rotation') || 0;updateProjection();if (newState.v && !newState.e && extent) {flyToNewExtent(extent, rotation);diff --git a/web/js/modules/animation/selectors.js b/web/js/modules/animation/selectors.jsindex f7b9b91d5..8b3d589cb 100644--- a/web/js/modules/animation/selectors.js+++ b/web/js/modules/animation/selectors.js@@ -25,7 +25,7 @@ export function getImageArray(dimensions,state) {- const { proj, legacy, date, layers, compare } = state;+ const { proj, map, date, layers, compare } = state;const { startDate, endDate, url } = gifComponentProps;const { boundaries, showDates } = gifComponentState;const { customInterval, interval, customDelta, delta, customSelected } = date;@@ -37,10 +37,7 @@ export function getImageArray(var j = 0;var src;var strDate;- var lonlats = imageUtilGetCoordsFromPixelValues(- boundaries,- legacy.map.ui.selected- );+ var lonlats = imageUtilGetCoordsFromPixelValues(boundaries, map.ui.selected);var layersArray;var opacities;let crs = proj.selected.crs;diff --git a/web/js/modules/animation/util.js b/web/js/modules/animation/util.jsindex 80acb2d8a..fcfc95b64 100644--- a/web/js/modules/animation/util.js+++ b/web/js/modules/animation/util.js@@ -1,108 +1,8 @@-import {- cloneDeep as lodashCloneDeep,- get,- round as lodashRound-} from 'lodash';+import { round as lodashRound } from 'lodash';import canvg from 'canvg-browser';import util from '../../util/util';import update from 'immutability-helper';-export function getAnimationParameterSetup(- parameters,- config,- models,- legacyState,- errors-) {- const loadedModel = lodashCloneDeep(models.anim.load(legacyState, errors)); // use legacy parser- const initialEnd = get(models, 'date.selected');- const initialStart = get(models, 'date.selectedB');-- return {- ab: {- stateKey: 'legacy.anim.rangeState.state',- initialState: 'off',- options: {- parse: () => {- return get(loadedModel, 'rangeState.state') || 'off';- },- serialize: () => {- return get(models, 'anim.rangeState.state') || 'off';- }- }- },- as: {- stateKey: 'legacy.anim.rangeState.startDate',- initialState: initialEnd,- type: 'date',- options: {- parse: () => {- return get(loadedModel, 'rangeState.startDate');- },- serialize: () => {- const isAnimationActive =- get(models, 'anim.rangeState.state') === 'on';- return isAnimationActive- ? get(models, 'anim.rangeState.startDate')- : undefined;- }- }- },- ae: {- stateKey: 'legacy.anim.rangeState.endDate',- initialState: initialStart,- type: 'date',- options: {- parse: () => {- return get(loadedModel, 'rangeState.endDate') || undefined;- },- serialize: () => {- const isAnimationActive =- get(models, 'anim.rangeState.state') === 'on';- return isAnimationActive- ? get(models, 'anim.rangeState.endDate')- : undefined;- }- }- },- av: {- stateKey: 'legacy.anim.rangeState.speed',- initialState: 3.0,- type: 'number',- options: {- serializeNeedsGlobalState: true,- parse: () => {- return get(loadedModel, 'anim.rangeState.speed') || 3.0;- },- serialize: (currentItemState, state) => {- const isAnimationActive =- get(models, 'anim.rangeState.state') === 'on';- return isAnimationActive- ? get(models, 'anim.rangeState.speed')- : undefined;- }- }- },- al: {- stateKey: 'legacy.anim.rangeState.loop',- type: 'bool',- initialState: false,- options: {- setAsEmptyItem: true,- parse: () => {- return get(loadedModel, 'rangeState.loop');- },- serialize: (currentItemState, state) => {- const isAnimationActive =- get(models, 'anim.rangeState.state') === 'on';- return isAnimationActive- ? get(models, 'anim.rangeState.loop')- : undefined;- }- }- }- };-}export function getStampProps(stampWidthRatio,breakPoint,diff --git a/web/js/modules/data/util.js b/web/js/modules/data/util.jsindex 605599c11..e69de29bb 100644--- a/web/js/modules/data/util.js+++ b/web/js/modules/data/util.js@@ -1,31 +0,0 @@-import { get } from 'redux-location-state/lib/helpers';-import { encode } from '../link/util';-export function getDataDownloadParameterSetup(- parameters,- config,- models,- legacyState,- errors-) {- const loadedModel = models.data.load(legacyState, errors);- return {- download: {- stateKey: 'legacy.data.active',- initialState: false,- type: 'bool',- options: {- delimiter: ',',- serializeNeedsGlobalState: true,- parse: () => {- return loadedModel.active || false;- },- serialize: (currentItemState, currentState) => {- const selected = get(currentState, 'legacy.data.selectedProduct');- if (!currentItemState) return false;-- return encode(selected);- }- }- }- };-}diff --git a/web/js/modules/map/constants.js b/web/js/modules/map/constants.jsindex c911efbd7..ade872bd1 100644--- a/web/js/modules/map/constants.js+++ b/web/js/modules/map/constants.js@@ -1,10 +1,14 @@import { getLeadingExtent, serializeExtent, parseMapExtent } from './util';export const RUNNING_DATA = 'MAP/RUNNING_DATA';export const CLEAR_RUNNING_DATA = 'MAP/CLEAR_RUNNING_DATA';+export const UPDATE_MAP_EXTENT = 'MAP/UPDATE_MAP_EXTENT';+export const UPDATE_MAP_UI = 'MAP/UPDATE_MAP_UI';+export const UPDATE_MAP_ROTATION = 'MAP/UPDATE_ROTATION';+const LEADING_EXTENT = getLeadingExtent();export const EXTENT_PARAM_SETUP = {- stateKey: 'legacy.map.extent',+ stateKey: 'map.extent',initialState: LEADING_EXTENT,type: 'array',options: {diff --git a/web/js/modules/map/reducers.js b/web/js/modules/map/reducers.jsindex a16af2a84..ae4dad786 100644--- a/web/js/modules/map/reducers.js+++ b/web/js/modules/map/reducers.js@@ -1,8 +1,17 @@import { assign as lodashAssign } from 'lodash';-import { RUNNING_DATA, CLEAR_RUNNING_DATA } from './constants';-+import {+ RUNNING_DATA,+ CLEAR_RUNNING_DATA,+ UPDATE_MAP_EXTENT,+ UPDATE_MAP_UI,+ UPDATE_MAP_ROTATION+} from './constants';+import update from 'immutability-helper';const INITIAL_STATE = {- runningDataObj: {}+ runningDataObj: {},+ ui: { selected: null },+ rotation: 0,+ extent: []};export default function mapReducer(state = INITIAL_STATE, action) {@@ -15,6 +24,12 @@ export default function mapReducer(state = INITIAL_STATE, action) {return lodashAssign({}, state, {runningDataObj: {}});+ case UPDATE_MAP_EXTENT:+ return update(state, { extent: { $set: action.extent } });+ case UPDATE_MAP_UI:+ return update(state, { ui: { $set: action.ui } });+ case UPDATE_MAP_ROTATION:+ return update(state, { rotation: { $set: action.rotation } });default:return state;}diff --git a/web/js/modules/map/selectors.js b/web/js/modules/map/selectors.jsindex b79302ab1..0a72ee174 100644--- a/web/js/modules/map/selectors.js+++ b/web/js/modules/map/selectors.js@@ -9,7 +9,7 @@ export function promiseImageryForTime(date, layers, state) {var frameState;var pixelRatio;var promiseArray;- const map = state.legacy.map;+ const map = state.map;var cache = map.ui.cache;var mapUi = map.ui;var selectedMap = map.ui.selected;diff --git a/web/js/modules/map/util.js b/web/js/modules/map/util.jsindex 5392fe689..10943e2c4 100644--- a/web/js/modules/map/util.js+++ b/web/js/modules/map/util.js@@ -19,7 +19,7 @@ export function getMapParameterSetup(const leadingExtent = getLeadingExtent();return {v: {- stateKey: 'legacy.map.extent',+ stateKey: 'map.extent',initialState: leadingExtent,type: 'array',options: {@@ -47,7 +47,7 @@ export function getMapParameterSetup(}},r: {- stateKey: 'legacy.map.rotation',+ stateKey: 'map.rotation',initialState: 0,options: {serializeNeedsGlobalState: true,