Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Properly pass set/clear vectorStyle actions in layer settings

ZachTRicec83f5a56676e
diff --git a/web/js/components/layer/settings/settings.js b/web/js/components/layer/settings/settings.js
index afe728a73..578739336 100644
--- a/web/js/components/layer/settings/settings.js
+++ b/web/js/components/layer/settings/settings.js
@@ -213,6 +213,8 @@ class LayerSettings extends React.Component {
renderVectorStyles() {
const {
setFilterRange,
+ setStyle,
+ clearStyle,
groupName,
layer,
vectorStyles
diff --git a/web/js/components/layer/settings/vector-style.js b/web/js/components/layer/settings/vector-style.js
index 4b6bfd1c4..30bd53b2b 100644
--- a/web/js/components/layer/settings/vector-style.js
+++ b/web/js/components/layer/settings/vector-style.js
@@ -15,16 +15,15 @@ class VectorStyleSelect extends React.Component {
* @param {String} id | custom VectorStyle Id
*/
onChangeVectorStyle(id) {
- const { layer, clearStyle, setStyle, index } = this.props;
-
+ const { layer, clearStyle, setStyle, groupName, index } = this.props;
// Applying customs takes a while and
// it looks more natural to make this async
// instead of waiting
setTimeout(function() {
- if (id === layer) {
- clearStyle(layer.id, index);
+ if (id === layer.id) {
+ clearStyle(layer.id, index, groupName);
} else {
- setStyle(layer.id, id, index);
+ setStyle(layer.id, id, index, groupName);
}
}, 0);
this.setState({ activeVectorStyle: id });
@@ -125,7 +124,8 @@ VectorStyleSelect.propTypes = {
canvas: PropTypes.object,
checkerBoard: PropTypes.object,
activeVectorStyle: PropTypes.string,
- vectorStyles: PropTypes.object
+ vectorStyles: PropTypes.object,
+ groupName: PropTypes.string
};
export default VectorStyleSelect;
diff --git a/web/js/map/layerbuilder.js b/web/js/map/layerbuilder.js
index 64472bbd3..c21b876f6 100644
--- a/web/js/map/layerbuilder.js
+++ b/web/js/map/layerbuilder.js
@@ -1,5 +1,4 @@
import util from '../util/util';
-import vectorStyles from '../modules/vector-styles/util';
import OlTileGridWMTS from 'ol/tilegrid/WMTS';
import OlSourceWMTS from 'ol/source/WMTS';
import OlSourceTileWMS from 'ol/source/TileWMS';
@@ -20,6 +19,10 @@ import {
getKey as getPaletteKeys,
getLookup as getPaletteLookup
} from '../modules/palettes/selectors';
+import {
+ isActive as isVectorStyleActive,
+ getKey as getVectorStyleKeys
+} from '../modules/vector-styles/selectors';
export function mapLayerBuilder(models, config, cache, mapUi, store) {
var self = {};
@@ -197,7 +200,7 @@ export function mapLayerBuilder(models, config, cache, mapUi, store) {
var date;
var layerId = def.id;
var projId = state.proj.id;
- var palette = '';
+ var style = '';
const activeGroupStr = options.group ? options.group : compare.activeString;
// Don't key by time if this is a static layer--it is valid for
@@ -208,9 +211,12 @@ export function mapLayerBuilder(models, config, cache, mapUi, store) {
);
}
if (isPaletteActive(def.id, activeGroupStr, state)) {
- palette = getPaletteKeys(def.id, undefined, state);
+ style = getPaletteKeys(def.id, undefined, state);
+ }
+ if (isVectorStyleActive(def.id, activeGroupStr, state)) {
+ style = getVectorStyleKeys(def.id, undefined, state);
}
- return [layerId, projId, date, palette, activeGroupStr].join(':');
+ return [layerId, projId, date, style, activeGroupStr].join(':');
};
/**
* Create a new WMTS Layer
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index e19e2c675..ae64f39ea 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -130,8 +130,7 @@ export function mapui(models, config, store, ui) {
case vectorStyleConstants.SET_FILTER_RANGE:
case vectorStyleConstants.SET_VECTORSTYLE:
case vectorStyleConstants.CLEAR_VECTORSTYLE:
- case vectorStyleConstants.REQUEST_VECTORSTYLE_SUCCESS:
- return updateLookup();
+ return reloadLayers();
case CALCULATE_RESPONSIVE_STATE:
return onResize();
case SELECT_DATE:
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index 015e67fb9..658628a8c 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -126,7 +126,7 @@ export function layerReducer(state = initialState, action) {
[layerGroupStr]: {
[layerIndex]: {
custom: {
- $set: action.paletteId
+ $set: action.vectorStyleId
}
}
}
diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.js
index 0a4fc40f1..6f9c7bedd 100644
--- a/web/js/modules/layers/util.js
+++ b/web/js/modules/layers/util.js
@@ -15,12 +15,14 @@ import {
getPaletteAttributeArray,
parseLegacyPalettes
} from '../palettes/util';
+import { getVectorStyleAttributeArray } from '../vector-styles/util';
import update from 'immutability-helper';
import util from '../../util/util';
export function serializeLayers(currentLayers, state, groupName) {
const layers = currentLayers;
const palettes = state.palettes[groupName];
+ const vectorStyles = state.vectorStyles[groupName];
return layers.map((def, i) => {
var item = {};
@@ -51,9 +53,19 @@ export function serializeLayers(currentLayers, state, groupName) {
palettes,
state
);
- item.attributes = paletteAttributeArray.length
- ? item.attributes.concat(paletteAttributeArray)
- : item.attributes;
+ const vectorStyleAttributeArray = getVectorStyleAttributeArray(
+ def.id,
+ vectorStyles,
+ state
+ );
+
+ if (paletteAttributeArray.length) {
+ item.attributes = item.attributes.concat(paletteAttributeArray);
+ } else if (vectorStyleAttributeArray.length) {
+ item.attributes = item.attributes.concat(vectorStyleAttributeArray);
+ } else {
+ item.attributes = item.attributes;
+ }
}
return util.appendAttributesForURL(item);
diff --git a/web/js/modules/vector-styles/actions.js b/web/js/modules/vector-styles/actions.js
index 0692572fa..857a41740 100644
--- a/web/js/modules/vector-styles/actions.js
+++ b/web/js/modules/vector-styles/actions.js
@@ -1,6 +1,4 @@
-import { requestAction } from '../core/actions';
import {
- REQUEST_VECTORSTYLE,
SET_FILTER_RANGE,
CLEAR_VECTORSTYLE,
SET_VECTORSTYLE,
@@ -12,27 +10,6 @@ import {
clearCustomSelector
} from './selectors';
-/**
- * Request vectorStyle using core request utility
- *
- * @param {String} id | Layer Id
- */
-export function requestVectorStyle(id) {
- return (dispatch, getState) => {
- const config = getState().config;
- var layer = config.layers[id];
- const vectorStyleID = layer.vectorStyle.id;
- const location = 'config/vectorStyles/' + vectorStyleID + '.json';
- return requestAction(
- dispatch,
- REQUEST_VECTORSTYLE,
- location,
- 'application/json',
- vectorStyleID
- );
- };
-}
-
/**
* @param {String} layerId
* @param {Object} props | contains min max and squash attributes
@@ -68,7 +45,6 @@ export function setFilterRange(layerId, props, index, groupName) {
* @param {String} groupName | layer group string
*/
export function setStyle(layerId, vectorStyleId, index, groupName) {
- // console.log(layerId, vectorStyleId, index, groupName);
return (dispatch, getState) => {
const state = getState();
const newActiveVectorStylesObj = setCustomSelector(
@@ -96,7 +72,6 @@ export function setStyle(layerId, vectorStyleId, index, groupName) {
* @param {String} groupName | layer group string
*/
export function clearStyle(layerId, index, groupName) {
- console.log(layerId, index, groupName)
return (dispatch, getState) => {
const { vectorStyles } = getState();
const newActiveVectorStylesObj = clearCustomSelector(
@@ -117,9 +92,9 @@ export function clearStyle(layerId, index, groupName) {
*
* @param {Object} customs | Custom VectorStyles from Config
*/
-export function loadedDefaultVectorStyles(defaults) {
+export function loadedDefaultVectorStyles(customs) {
return {
type: LOADED_CUSTOM_VECTORSTYLES,
- default: defaults
+ custom: customs
};
}
diff --git a/web/js/modules/vector-styles/constants.js b/web/js/modules/vector-styles/constants.js
index c6282fe5d..cc6f20a7b 100644
--- a/web/js/modules/vector-styles/constants.js
+++ b/web/js/modules/vector-styles/constants.js
@@ -1,8 +1,3 @@
-export const REQUEST_VECTORSTYLE = 'VECTORSTYLES/REQUEST_VECTORSTYLE';
-export const REQUEST_VECTORSTYLE_START = 'VECTORSTYLES/REQUEST_VECTORSTYLE_START';
-export const REQUEST_VECTORSTYLE_SUCCESS = 'VECTORSTYLES/REQUEST_VECTORSTYLE_SUCCESS';
-export const REQUEST_VECTORSTYLE_FAILURE = 'VECTORSTYLES/REQUEST_VECTORSTYLE_FAILURE';
-
export const VECTORSTYLE_CHANGE = 'VECTORSTYLES/CHANGE_OF_ACTIVE_VECTORSTYLE';
export const SET_FILTER_RANGE = 'VECTORSTYLES/SET_FILTER_RANGE';
export const CLEAR_VECTORSTYLE = 'VECTORSTYLES/CLEAR_VECTORSTYLE';
diff --git a/web/js/modules/vector-styles/reducers.js b/web/js/modules/vector-styles/reducers.js
index 0168970b7..8dd1bd69a 100644
--- a/web/js/modules/vector-styles/reducers.js
+++ b/web/js/modules/vector-styles/reducers.js
@@ -1,20 +1,15 @@
import { assign as lodashAssign, get as lodashGet } from 'lodash';
import {
- REQUEST_VECTORSTYLE_SUCCESS,
SET_VECTORSTYLE,
- REQUEST_VECTORSTYLE_START,
SET_FILTER_RANGE,
LOADED_CUSTOM_VECTORSTYLES
} from './constants';
-import update from 'immutability-helper';
-import util from '../../util/util';
-const browser = util.browser;
+// import update from 'immutability-helper';
+// import util from '../../util/util';
export const defaultVectorStyleState = {
custom: {},
active: {},
- activeB: {},
- isLoading: {},
- supported: !(browser.ie || !browser.webWorkers || !browser.cors)
+ activeB: {}
};
export function getInitialVectorStyleState(config) {
const custom = lodashGet(config, 'vectorStyles') || {};
@@ -26,20 +21,6 @@ export function getInitialVectorStyleState(config) {
export function vectorStyleReducer(state = defaultVectorStyleState, action) {
const groupName = action.groupName || 'active';
switch (action.type) {
- case REQUEST_VECTORSTYLE_START:
- return lodashAssign({}, state, {
- isLoading: update(state.isLoading, {
- [action.id]: { $set: true }
- })
- });
- case REQUEST_VECTORSTYLE_SUCCESS:
- let isLoading = update(state.isLoading, { $unset: [action.id] });
- return lodashAssign({}, state, {
- rendered: lodashAssign({}, state.rendered, {
- [action.id]: action.response
- }),
- isLoading
- });
case SET_FILTER_RANGE:
return lodashAssign({}, state, {
[groupName]: action.vectorStyles
diff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.js
index e8e7d868c..15ee2e854 100644
--- a/web/js/modules/vector-styles/selectors.js
+++ b/web/js/modules/vector-styles/selectors.js
@@ -2,7 +2,6 @@ import {
get as lodashGet,
isUndefined as lodashIsUndefined,
each as lodashEach,
- // parseInt as lodashParseInt,
cloneDeep as lodashCloneDeep
} from 'lodash';
import { getMinValue, getMaxValue } from './util';
@@ -35,15 +34,15 @@ export function getVectorStyle(layerId, index, groupStr, state) {
export function getRenderedVectorStyle(layerId, index, state) {
const { config, vectorStyles } = state;
var name = lodashGet(config, `layers.${layerId}.vectorStyle.id`);
- var vectorStyle = vectorStyles[name];
+ var vectorStyle = vectorStyles.custom[name];
if (!vectorStyle) {
throw new Error(name + ' Is not a rendered vectorStyle');
}
- // if (!lodashIsUndefined(index)) {
- // if (vectorStyle.layers) {
- // vectorStyle = vectorStyle.layers[index];
- // }
- // }
+ if (!lodashIsUndefined(index)) {
+ if (vectorStyle.layers) {
+ vectorStyle = vectorStyle.layers[index];
+ }
+ }
return vectorStyle;
}
diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.js
index 33dbd49db..5e708e334 100644
--- a/web/js/modules/vector-styles/util.js
+++ b/web/js/modules/vector-styles/util.js
@@ -1,127 +1,120 @@
import update from 'immutability-helper';
import {
each as lodashEach,
- find as lodashFind,
+ // find as lodashFind,
assign as lodashAssign
} from 'lodash';
import {
- setDefault as setDefaultSelector,
+ setCustomSelector,
getCount,
setRange as setRangeSelector,
findIndex as findVectorStyleExtremeIndex
} from './selectors';
-import util from '../../util/util';
+// import util from '../../util/util';
-export function loadRenderedVectorStyle(config, layerId) {
- var layer = config.layers[layerId];
- return util.load.config(config.vectorStyles.rendered,
- layer.vectorStyle.id, 'config/vectorstyles/' + layer.vectorStyle.id + '.json');
-}
-export function loadDefault(config) {
- console.log('vectorStyles.loadDefault');
- return util.load.config(
- config.vectorStyles.default,
- 'OrbitTracks',
- 'config/vectorstyles/OrbitTracks.json'
- );
-}
-
-export function parseVectorStyles(state, errors, config) {
- if (state.vectorStyles) {
- var parts = state.vectorStyles.split('~');
- lodashEach(parts, function(part) {
- var items = part.split(',');
- var layerId = items[0];
- var vectorStyleId = items[1];
- if (!config.layers[layerId]) {
- errors.push({
- message: 'Invalid layer for vectorStyle ' + vectorStyleId + ': ' + layerId
- });
- } else if (!config.layers[layerId].vectorStyle) {
- errors.push({
- message: 'Layer ' + layerId + ' does not ' + 'support vectorStyles'
- });
- } else {
- var layer = lodashFind(state.l, {
- id: layerId
- });
- if (layer) {
- layer.attributes.push({
- id: 'vectorStyle',
- value: vectorStyleId
- });
- } else {
- errors.push({
- message: 'Layer ' + layerId + ' is not ' + 'active'
- });
- }
- }
- });
- delete state.vectorStyles;
- }
-}
-
-// export function getVectorStyleAttributeArray(layerId, vectorStyles, state) {
-// const count = getCount(layerId, state);
-// const DEFAULT_OBJ = { isActive: false, value: undefined };
-// let palObj = lodashAssign({}, { key: 'custom', array: [] }, DEFAULT_OBJ);
-// let minObj = lodashAssign({}, { key: 'min', array: [] }, DEFAULT_OBJ);
-// let maxObj = lodashAssign({}, { key: 'max', array: [] }, DEFAULT_OBJ);
-// let squashObj = lodashAssign({}, { key: 'squash', array: [] }, DEFAULT_OBJ);
-// let attrArray = [];
-// for (var i = 0; i < count; i++) {
-// let vectorStyleDef = vectorStyles[layerId].maps[i];
-// let entryLength = vectorStyleDef.entries.values.length;
-// let maxValue = vectorStyleDef.max
-// ? vectorStyleDef.entries.values[vectorStyleDef.max || entryLength]
-// : undefined;
-// let minValue = vectorStyleDef.min
-// ? vectorStyleDef.entries.values[vectorStyleDef.min || 0]
-// : undefined;
-// palObj = createVectorStyleAttributeObject(
-// vectorStyleDef,
-// vectorStyleDef.custom,
-// palObj,
-// count
-// );
-// maxObj = createVectorStyleAttributeObject(vectorStyleDef, maxValue, maxObj, count);
-// minObj = createVectorStyleAttributeObject(vectorStyleDef, minValue, minObj, count);
+// export function loadRenderedVectorStyle(config, layerId) {
+// var layer = config.layers[layerId];
+// return util.load.config(config.vectorStyles.rendered,
+// layer.vectorStyle.id, 'config/vectorstyles/' + layer.vectorStyle.id + '.json');
+// }
+// export function loadDefault(config) {
+// console.log('vectorStyles.loadDefault');
+// return util.load.config(
+// config.vectorStyles.default,
+// 'OrbitTracks',
+// 'config/vectorstyles/OrbitTracks.json'
+// );
+// }
-// squashObj = createVectorStyleAttributeObject(
-// vectorStyleDef,
-// true,
-// squashObj,
-// count
-// );
+// export function parseVectorStyles(state, errors, config) {
+// if (state.vectorStyles) {
+// var parts = state.vectorStyles.split('~');
+// lodashEach(parts, function(part) {
+// var items = part.split(',');
+// var layerId = items[0];
+// var vectorStyleId = items[1];
+// if (!config.layers[layerId]) {
+// errors.push({
+// message: 'Invalid layer for vectorStyle ' + vectorStyleId + ': ' + layerId
+// });
+// } else if (!config.layers[layerId].vectorStyle) {
+// errors.push({
+// message: 'Layer ' + layerId + ' does not ' + 'support vectorStyles'
+// });
+// } else {
+// var layer = lodashFind(state.l, {
+// id: layerId
+// });
+// if (layer) {
+// layer.attributes.push({
+// id: 'vectorStyle',
+// value: vectorStyleId
+// });
+// } else {
+// errors.push({
+// message: 'Layer ' + layerId + ' is not ' + 'active'
+// });
+// }
+// }
+// });
+// delete state.vectorStyles;
// }
-
-// [palObj, minObj, maxObj, squashObj].forEach(obj => {
-// if (obj.isActive) {
-// attrArray.push({
-// id: obj.key === 'custom' ? 'vectorStyle' : obj.key,
-// value: obj.value
-// });
-// }
-// });
-// return attrArray;
// }
-// const createVectorStyleAttributeObject = function(def, value, attrObj, count) {
-// const key = attrObj.key;
-// const attrArray = attrObj.array;
-// let hasAtLeastOnePair = attrObj.isActive;
-// value = isArray(value) ? value.join(',') : value;
-// if (def[key] && value) {
-// attrArray.push(value);
-// hasAtLeastOnePair = true;
-// } else if (count > 1) {
-// attrArray.push('');
-// }
-// return lodashAssign({}, attrObj, {
-// array: attrArray,
-// isActive: hasAtLeastOnePair,
-// value: attrArray.join(';')
-// });
-// };
+
+export function getVectorStyleAttributeArray(layerId, vectorStyles, state) {
+ const count = getCount(layerId, state);
+ console.log(state);
+ const DEFAULT_OBJ = { isActive: false, value: undefined };
+ let palObj = lodashAssign({}, { key: 'custom', array: [] }, DEFAULT_OBJ);
+ let minObj = lodashAssign({}, { key: 'min', array: [] }, DEFAULT_OBJ);
+ let maxObj = lodashAssign({}, { key: 'max', array: [] }, DEFAULT_OBJ);
+ let attrArray = [];
+ for (var i = 0; i < count; i++) {
+ let vectorStyleDef = vectorStyles[layerId].maps[i];
+ let entryLength = vectorStyleDef.entries.values.length;
+ let maxValue = vectorStyleDef.max
+ ? vectorStyleDef.entries.values[vectorStyleDef.max || entryLength]
+ : undefined;
+ let minValue = vectorStyleDef.min
+ ? vectorStyleDef.entries.values[vectorStyleDef.min || 0]
+ : undefined;
+ palObj = createVectorStyleAttributeObject(
+ vectorStyleDef,
+ vectorStyleDef.custom,
+ palObj,
+ count
+ );
+ maxObj = createVectorStyleAttributeObject(vectorStyleDef, maxValue, maxObj, count);
+ minObj = createVectorStyleAttributeObject(vectorStyleDef, minValue, minObj, count);
+ }
+
+ [palObj, minObj, maxObj].forEach(obj => {
+ if (obj.isActive) {
+ attrArray.push({
+ id: obj.key === 'custom' ? 'vectorStyle' : obj.key,
+ value: obj.value
+ });
+ }
+ });
+ return attrArray;
+}
+const createVectorStyleAttributeObject = function(def, value, attrObj, count) {
+ const key = attrObj.key;
+ const attrArray = attrObj.array;
+ let hasAtLeastOnePair = attrObj.isActive;
+ value = isArray(value) ? value.join(',') : value;
+ if (def[key] && value) {
+ attrArray.push(value);
+ hasAtLeastOnePair = true;
+ } else if (count > 1) {
+ attrArray.push('');
+ }
+ return lodashAssign({}, attrObj, {
+ array: attrArray,
+ isActive: hasAtLeastOnePair,
+ value: attrArray.join(';')
+ });
+};
export function loadVectorStyles(permlinkState, state) {
var stateArray = [{ stateStr: 'l', groupStr: 'active' }];
if (permlinkState.l1) {
@@ -140,7 +133,7 @@ export function loadVectorStyles(permlinkState, state) {
if (layerDef.custom) {
lodashEach(layerDef.custom, function(value, index) {
try {
- let newVectorStyles = setDefaultSelector(
+ let newVectorStyles = setCustomSelector(
layerId,
value,
index,