Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add documentation

Benjamin King7908064ff21a
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index ec8ce4d3f..6e09dba05 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -40,6 +40,10 @@ function lastAction(state = null, action) {
return action;
}
+/**
+ * Access to page size so various resize listeners are
+ * no longer necessary
+ */
const responsiveStateReducer = createResponsiveStateReducer(
{
extraSmall: 500,
@@ -55,6 +59,14 @@ const responsiveStateReducer = createResponsiveStateReducer(
})
}
);
+/**
+ * Get initial module states based on config
+ * and parameters
+ *
+ * @param {Object} models | Legacy models
+ * @param {Object} config
+ * @param {Object} parameters | parameters parsed from permalink
+ */
export function getInitialState(models, config, parameters) {
const eventsIgnoreArray = {
ignore: lodashGet(config, 'naturalEvents.skip') || []
@@ -64,7 +76,6 @@ export function getInitialState(models, config, parameters) {
parameters,
config,
models,
- legacy: models,
date: getDateInitialState(config),
animation: getAnimationInitialState(config),
proj: getProjInitialState(config),
@@ -104,6 +115,9 @@ const reducers = {
lastAction: lastAction
};
const appReducer = combineReducers(reducers);
+/**
+ * Top level reducer function w/ option to reset state
+ */
export default (state, action) => {
if (action.type === 'APP_RESET') {
state = undefined;
diff --git a/web/js/modules/palettes/util.js b/web/js/modules/palettes/util.js
index 27ef2ca5e..3af53f7ee 100644
--- a/web/js/modules/palettes/util.js
+++ b/web/js/modules/palettes/util.js
@@ -17,6 +17,10 @@ import {
import util from '../../util/util';
import Promise from 'bluebird';
+/**
+ * Create checkerboard canvas pattern object
+ * to use on background of legend colorbars
+ */
export function getCheckerboard() {
var size = 2;
var canvas = document.createElement('canvas');
@@ -38,6 +42,7 @@ export function getCheckerboard() {
return g.createPattern(canvas, 'repeat');
}
+
export function palettesTranslate(source, target) {
var translation = [];
lodashEach(source, function(color, index) {
@@ -117,6 +122,15 @@ export function getMinValue(v) {
export function getMaxValue(v) {
return v.length ? v[v.length - 1] : v;
}
+/**
+ * Legacy palette parser
+ * &palettes=something no longer promoted
+ * but is still supported
+ *
+ * @param {Object} state
+ * @param {Object} errors
+ * @param {Object} config
+ */
export function parsePalettes(state, errors, config) {
if (state.palettes) {
var parts = state.palettes.split('~');
@@ -155,6 +169,15 @@ export function isSupported() {
var browser = util.browser;
return !(browser.ie || !browser.webWorkers || !browser.cors);
}
+/**
+ * Serialize palette info for layer
+ *
+ * @param {String} layerId
+ * @param {Object} palettes active|activeB palettes
+ * @param {Object} state
+ *
+ * @returns {Array}
+ */
export function getPaletteAttributeArray(layerId, palettes, state) {
const count = getCount(layerId, state);
const DEFAULT_OBJ = { isActive: false, value: undefined };
@@ -165,7 +188,9 @@ export function getPaletteAttributeArray(layerId, palettes, state) {
let attrArray = [];
for (var i = 0; i < count; i++) {
let paletteDef = palettes[layerId].maps[i];
- let entryLength = lodashSize(lodashGet(paletteDef, 'entries.values')) || lodashSize(lodashGet(paletteDef, 'entries.colors'));
+ let entryLength =
+ lodashSize(lodashGet(paletteDef, 'entries.values')) ||
+ lodashSize(lodashGet(paletteDef, 'entries.colors'));
let maxValue = paletteDef.max
? paletteDef.entries.values[paletteDef.max || entryLength]
: undefined;
@@ -216,6 +241,14 @@ const createPaletteAttributeObject = function(def, value, attrObj, count) {
value: attrArray.join(';')
});
};
+
+/**
+ * Initiate palette from layer information that was derived from the
+ * permalink in the layerParser
+ *
+ * @param {Object} permlinkState | parameters parsed from permalink
+ * @param {Object} state
+ */
export function loadPalettes(permlinkState, state) {
var stateArray = [{ stateStr: 'l', groupStr: 'active' }];
if (!isSupported()) {
@@ -332,6 +365,13 @@ export function mapLocationToPaletteState(
}
return stateFromLocation;
}
+/**
+ * Request palettes before page load
+ * @param {Array} layersArray Array of active layers
+ * @param {Object} renderedPalettes
+ * @param {Boolean} customLoaded
+ * @returns {Promise}
+ */
export function preloadPalettes(layersArray, renderedPalettes, customLoaded) {
let rendered = renderedPalettes || {};
customLoaded = customLoaded || false;
diff --git a/web/js/modules/projection/util.js b/web/js/modules/projection/util.js
index f4e28fe74..4a191f362 100644
--- a/web/js/modules/projection/util.js
+++ b/web/js/modules/projection/util.js
@@ -11,6 +11,14 @@ export function getProjInitialState(config) {
selected: selected || {}
};
}
+/**
+ * Update 'proj.selected' object from config based
+ * on updated states `proj.id` value
+ *
+ * @param {Object} parameters | parameters parsed from permalink
+ * @param {Object} stateFromLocation | State derived from permalink parsers
+ * @param {Object} state | initial state before location POP action
+ */
export function mapLocationToProjState(parameters, stateFromLocation, state) {
const projId = lodashGet(stateFromLocation, 'proj.id');
if (projId) {
diff --git a/web/js/modules/sidebar/util.js b/web/js/modules/sidebar/util.js
index fa88c9c71..e55bef64b 100644
--- a/web/js/modules/sidebar/util.js
+++ b/web/js/modules/sidebar/util.js
@@ -1,5 +1,14 @@
import update from 'immutability-helper';
import { assign as lodashAssign } from 'lodash';
+
+/**
+ * Update sidebar state when location-pop action occurs
+ *
+ * @param {Object} parameters | parameters parsed from permalink
+ * @param {Object} stateFromLocation | State derived from permalink parsers
+ * @param {Object} state | initial state before location POP action
+ * @param {Object} config
+ */
export function mapLocationToSidebarState(
parameters,
stateFromLocation,
diff --git a/web/js/modules/tour/actions.js b/web/js/modules/tour/actions.js
index e4ca9f103..f85b6cb01 100644
--- a/web/js/modules/tour/actions.js
+++ b/web/js/modules/tour/actions.js
@@ -1,4 +1,5 @@
import { START, UPDATE_SELECTED, END_TOUR } from './constants';
+
export function startTour() {
return {
type: START
diff --git a/web/js/modules/tour/util.js b/web/js/modules/tour/util.js
index 12d286592..329b00000 100644
--- a/web/js/modules/tour/util.js
+++ b/web/js/modules/tour/util.js
@@ -1,8 +1,15 @@
import googleTagManager from 'googleTagManager';
import util from '../../util/util';
-
+/**
+ * Determine if tour should be shown based on
+ * user's browser and is 'hidestore' key is in localStorage
+ *
+ * @param {Object} config
+ *
+ * @returns {Boolean}
+ */
export function checkTourBuildTimestamp(config) {
- if (!util.browser.localStorage) return;
+ if (!util.browser.localStorage) return false;
var hideTour = localStorage.getItem('hideTour');
// Don't start tour if coming in via a permalink