Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Only subscribe to store once #1755

Benjamin Kingbac116ade43c
diff --git a/web/js/combine-ui.js b/web/js/combine-ui.js
index 58b374283..8855ea83f 100644
--- a/web/js/combine-ui.js
+++ b/web/js/combine-ui.js
@@ -3,7 +3,6 @@ import { mapui } from './map/ui';
import { mapAnimate } from './map/animate';
import { dataUi } from './map/data/ui';
import naturalEventsUI from './map/natural-events/ui';
-
/**
* Legacy UI Rendering
* @param {Object} models | Legacy Models Object
@@ -12,16 +11,15 @@ import naturalEventsUI from './map/natural-events/ui';
*/
export function combineUi(models, config, MapMouseEvents, store) {
let ui = {};
+ ui.events = util.events();
+ const subscribeToStore = function() {
+ const state = store.getState();
+ const action = state.lastAction;
+ return ui.events.trigger('last-action', action);
+ };
+ store.subscribe(subscribeToStore);
ui.map = mapui(models, config, store, ui);
ui.map.animate = mapAnimate(config, ui, store);
- if (config.features.tour) {
- // ui.alert = alertUi(ui, config);
- // ui.tour = tourUi(models, ui, config);
- }
- // ui.activeLayers = layersActive(models, ui, config);
- // ui.addModal = layersModal(models, ui, config);
- // ui.layerSettingsModal = layersOptions(models, ui, config);
- // Test via a getter in the options object to see if the passive property is accessed
ui.supportsPassive = false;
try {
var opts = Object.defineProperty({}, 'passive', {
diff --git a/web/js/map/data/cmr.js b/web/js/map/data/cmr.js
index 67bbcb349..a26211197 100644
--- a/web/js/map/data/cmr.js
+++ b/web/js/map/data/cmr.js
@@ -1,5 +1,4 @@
import util from '../../util/util';
-import { getActiveTime } from '../../modules/data/util';
import OlGeomPolygon from 'ol/geom/Polygon';
export const REL_DATA = 'http://esipfed.org/ns/fedsearch/1.1/data#';
export const REL_METADATA = 'http://esipfed.org/ns/fedsearch/1.1/metadata#';
diff --git a/web/js/map/data/ui.js b/web/js/map/data/ui.js
index 49c023930..38a2ec3c4 100644
--- a/web/js/map/data/ui.js
+++ b/web/js/map/data/ui.js
@@ -38,9 +38,7 @@ export function dataUi(store, ui, config) {
self.selector = '#wv-data';
self.id = 'wv-data';
- const subscribeToStore = function() {
- const state = store.getState();
- const action = state.lastAction;
+ const subscribeToStore = function(action) {
switch (action.type) {
case CHANGE_SIDEBAR_TAB:
return action.activeTab === 'download' ? onActivate() : mapController ? onDeactivate() : '';
@@ -123,7 +121,7 @@ export function dataUi(store, ui, config) {
};
var init = function() {
const sidebarState = store.getState().sidebar;
- store.subscribe(subscribeToStore);
+ ui.events.on('last-action', subscribeToStore);
self.events.on('query', onQuery)
.on('queryResults', onQueryResults)
.on('queryError', onQueryError)
@@ -167,7 +165,7 @@ export function dataUi(store, ui, config) {
self.active = true;
self.events.trigger('activate');
if (!mapController) {
- mapController = dataMap(store, maps, self);
+ mapController = dataMap(store, maps, self, ui);
}
query();
};
diff --git a/web/js/map/datelinebuilder.js b/web/js/map/datelinebuilder.js
index 4b7f1299a..78fd14854 100644
--- a/web/js/map/datelinebuilder.js
+++ b/web/js/map/datelinebuilder.js
@@ -20,7 +20,7 @@ var map,
textRight,
proj;
-export function mapDateLineBuilder(models, config, store) {
+export function mapDateLineBuilder(models, config, store, ui) {
var self = {};
/*
* Sets globals and event listeners
@@ -39,14 +39,13 @@ export function mapDateLineBuilder(models, config, store) {
* Suscribe to redux store and listen for
* specific action types
*/
- const subscribeToStore = function() {
- const state = store.getState();
- const action = state.lastAction;
- const selectedDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
- const date = state.date[selectedDateStr];
+ const subscribeToStore = function(action) {
switch (action.type) {
case SELECT_DATE:
case COMPARE_CHANGE_STATE:
+ let state = store.getState();
+ let selectedDateStr = state.compare.isCompareA ? 'selected' : 'selectedB';
+ let date = state.date[selectedDateStr];
return updateDate(date);
case CHANGE_PROJECTION:
proj = action.id;
@@ -78,7 +77,7 @@ export function mapDateLineBuilder(models, config, store) {
}
updateLineVisibility(false);
});
- store.subscribe(subscribeToStore);
+ ui.events.on('last-action', subscribeToStore);
};
var isGeoProjection = function() {
if (proj === 'geographic') {
diff --git a/web/js/map/natural-events/ui.js b/web/js/map/natural-events/ui.js
index b04a3c2ba..c5441ca03 100644
--- a/web/js/map/natural-events/ui.js
+++ b/web/js/map/natural-events/ui.js
@@ -36,10 +36,9 @@ export default function naturalEventsUI(ui, config, store, models) {
* Suscribe to redux store and listen for
* specific action types
*/
- const subscribeToStore = function() {
+ const subscribeToStore = function(action) {
const state = store.getState();
const events = state.events;
- const action = state.lastAction;
const {
requestedEvents,
requestedEventSources,
@@ -118,7 +117,7 @@ export default function naturalEventsUI(ui, config, store, models) {
}
};
// get events for projection change
- const onProjChange = function(e) {
+ const onProjChange = function(id) {
const state = store.getState();
map = ui.map.selected;
view = map.getView();
@@ -211,7 +210,7 @@ export default function naturalEventsUI(ui, config, store, models) {
map = ui.map.selected;
// Display loading information for user feedback on slow network
view = map.getView();
- store.subscribe(subscribeToStore);
+ ui.events.on('last-action', subscribeToStore);
};
var getZoomPromise = function(
event,
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 8c10be6bd..085a07fb1 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -54,7 +54,7 @@ export function mapui(models, config, store, ui) {
var self = {};
var cache;
var rotation = new MapRotate(self, models, store);
- var dateline = mapDateLineBuilder(models, config, store);
+ var dateline = mapDateLineBuilder(models, config, store, ui);
var precache = mapPrecacheTile(models, config, cache, self);
var compareMapUi = mapCompare(config, store);
var dataRunner = (self.runningdata = new MapRunningData(
@@ -83,9 +83,7 @@ export function mapui(models, config, store, ui) {
* Suscribe to redux store and listen for
* specific action types
*/
- const subscribeToStore = function() {
- const state = store.getState();
- const action = state.lastAction;
+ const subscribeToStore = function(action) {
switch (action.type) {
case layerConstants.ADD_LAYER:
let def = lodashFind(action.layers, { id: action.id });
@@ -145,7 +143,7 @@ export function mapui(models, config, store, ui) {
self.proj[proj.id] = map;
});
models.map.events.on('update-layers', reloadLayers);
- store.subscribe(subscribeToStore);
+ ui.events.on('last-action', subscribeToStore);
updateProjection(true);
};
const flyToNewExtent = function(extent, rotation) {