Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Reduxify runningData #1623

Benjamin King1d3260dbd630
diff --git a/web/js/components/sidebar/layers/layer.js b/web/js/components/sidebar/layers/layer.js
index c0826fc82..c5b3d4aae 100644
--- a/web/js/components/sidebar/layers/layer.js
+++ b/web/js/components/sidebar/layers/layer.js
@@ -285,7 +285,7 @@ function mapStateToProps(state, ownProps) {
index,
layerGroupName
} = ownProps;
- const { palettes, config } = state;
+ const { palettes, config, map } = state;
const hasPalette = !lodashIsEmpty(layer.palette);
const renderedPalettes = palettes.rendered;
const paletteName = lodashGet(config, `layers.${layer.id}.palette.id`);
@@ -294,6 +294,7 @@ function mapStateToProps(state, ownProps) {
? getLegends(layer.id, layerGroupName, state)
: [];
const isCustomPalette = hasPalette && palettes.custom[layer.id];
+
return {
layer,
isDisabled,
@@ -310,7 +311,8 @@ function mapStateToProps(state, ownProps) {
hasPalette,
getPalette: (layerId, index) => {
return getPalette(layer.id, index, layerGroupName, state);
- }
+ },
+ runningObject: map.runningDataObj[layer.id]
};
}
diff --git a/web/js/map/runningdata.js b/web/js/map/runningdata.js
index e8db3fb55..fa5c66056 100644
--- a/web/js/map/runningdata.js
+++ b/web/js/map/runningdata.js
@@ -2,6 +2,10 @@ import util from '../util/util';
import lodashIsEqual from 'lodash/isEqual';
import lodashIsEmpty from 'lodash/isEmpty';
import { getPalette } from '../modules/palettes/selectors';
+import {
+ runningData as runningDataAction,
+ clearRunningData as clearRunningDataAction
+} from '../modules/map/actions';
export function MapRunningData(models, compareUi, store) {
var self;
@@ -14,7 +18,7 @@ export function MapRunningData(models, compareUi, store) {
self.clearAll = function() {
if (!lodashIsEmpty(dataObj)) {
dataObj = {};
- models.map.events.trigger('data-running', dataObj);
+ store.dispatch(clearRunningDataAction());
}
};
/**
@@ -78,7 +82,7 @@ export function MapRunningData(models, compareUi, store) {
});
if (!lodashIsEqual(activeLayerObj, dataObj)) {
dataObj = activeLayerObj;
- models.map.events.trigger('data-running', dataObj);
+ store.dispatch(runningDataAction(dataObj));
}
};
return self;
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 096555785..998aa8972 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -1014,6 +1014,7 @@ export function mapui(models, config, store) {
function onMouseMove(e) {
var coords;
var pixels;
+ const state = store.getState();
if (compareMapUi && compareMapUi.dragging) return;
// if mobile return
if (util.browser.small) {
@@ -1044,10 +1045,9 @@ export function mapui(models, config, store) {
}
// Don't add data runners if we're on the events or data tabs, or if map is animating
var isEventsTabActive =
- typeof models.naturalEvents !== 'undefined' &&
- models.naturalEvents.active;
+ typeof state.events !== 'undefined' && state.events.active;
var isDataTabActive =
- typeof models.data !== 'undefined' && models.data.active;
+ typeof state.data !== 'undefined' && state.data.active;
var isMapAnimating =
typeof models.anim !== 'undefined' && models.anim.rangeState.playing;
if (isEventsTabActive || isDataTabActive || isMapAnimating) return;
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index c9a30f773..c70e608c9 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -13,6 +13,7 @@ import {
eventRequestResponse
} from './natural-events/reducers';
import tourReducer from './tour/reducers';
+import mapReducer from './map/reducers';
import {
notificationsRequest,
notificationsReducer
@@ -82,6 +83,7 @@ const reducers = {
data: dataDownloadReducer,
palettes: paletteReducer,
tour: tourReducer,
+ map: mapReducer,
requestedEvents,
requestedEventSources,
requestedEventCategories,
diff --git a/web/js/modules/map/actions.js b/web/js/modules/map/actions.js
new file mode 100644
index 000000000..73d754ed6
--- /dev/null
+++ b/web/js/modules/map/actions.js
@@ -0,0 +1,14 @@
+import { RUNNING_DATA, CLEAR_RUNNING_DATA } from './constants';
+
+export function runningData(payload) {
+ return {
+ type: RUNNING_DATA,
+ payload: payload
+ };
+}
+
+export function clearRunningData() {
+ return {
+ type: CLEAR_RUNNING_DATA
+ };
+}
diff --git a/web/js/modules/map/constants.js b/web/js/modules/map/constants.js
index e88c0f420..c911efbd7 100644
--- a/web/js/modules/map/constants.js
+++ b/web/js/modules/map/constants.js
@@ -1,4 +1,6 @@
import { getLeadingExtent, serializeExtent, parseMapExtent } from './util';
+export const RUNNING_DATA = 'MAP/RUNNING_DATA';
+export const CLEAR_RUNNING_DATA = 'MAP/CLEAR_RUNNING_DATA';
const LEADING_EXTENT = getLeadingExtent();
export const EXTENT_PARAM_SETUP = {
diff --git a/web/js/modules/map/reducers.js b/web/js/modules/map/reducers.js
new file mode 100644
index 000000000..a16af2a84
--- /dev/null
+++ b/web/js/modules/map/reducers.js
@@ -0,0 +1,21 @@
+import { assign as lodashAssign } from 'lodash';
+import { RUNNING_DATA, CLEAR_RUNNING_DATA } from './constants';
+
+const INITIAL_STATE = {
+ runningDataObj: {}
+};
+
+export default function mapReducer(state = INITIAL_STATE, action) {
+ switch (action.type) {
+ case RUNNING_DATA:
+ return lodashAssign({}, state, {
+ runningDataObj: action.payload
+ });
+ case CLEAR_RUNNING_DATA:
+ return lodashAssign({}, state, {
+ runningDataObj: {}
+ });
+ default:
+ return state;
+ }
+}
diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.js
index fe542b4ff..a969e9dac 100644
--- a/web/js/modules/palettes/util.js
+++ b/web/js/modules/palettes/util.js
@@ -2,7 +2,8 @@ import update from 'immutability-helper';
import {
each as lodashEach,
find as lodashFind,
- assign as lodashAssign
+ assign as lodashAssign,
+ isArray
} from 'lodash';
import {
setCustom as setCustomSelector,