Interactive interface for browsing global, full-resolution satellite imagery
Retain vectorStyle in URL and set checkbox in settings
ZachTRicebe2cf2337137
diff --git a/web/js/components/layer/settings/settings.js b/web/js/components/layer/settings/settings.jsindex 1167383bb..575cf26f6 100644--- a/web/js/components/layer/settings/settings.js+++ b/web/js/components/layer/settings/settings.js@@ -225,7 +225,10 @@ class LayerSettings extends React.Component {const start = 0; // Placeholder// const end = vectorStyle.max || max;const end = max; // Placeholder-+ var customStyle;+ if (layer.custom && layer.custom[0]) {+ customStyle = layer.custom[0];+ }return (<React.Fragment><VectorFilter@@ -241,7 +244,7 @@ class LayerSettings extends React.Component {<VectorStylesetStyle={setStyle}clearStyle={clearStyle}- activeVectorStyle={layer.id}+ activeVectorStyle={customStyle || layer.id}layer={layer}index={0}groupName={groupName}diff --git a/web/js/location.js b/web/js/location.jsindex 72378eaf2..69f139957 100644--- a/web/js/location.js+++ b/web/js/location.js@@ -75,6 +75,7 @@ export const mapLocationToState = (state, location) => {state,config);+// one level deep merge of newState with defaultStatefor (var key in stateFromLocation) {const obj = lodashAssign({}, state[key], stateFromLocation[key]);diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex 5f1f2aef7..29b97c0bb 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -335,6 +335,10 @@ const createLayerArrayFromState = function(state, config) {let values = util.toArray(attr.value.split(';'));custom = values;}+ if (attr.id === 'vectorStyle') {+ let values = util.toArray(attr.value.split(';'));+ custom = values;+ }});layerArray = addLayer(layerDef.id,diff --git a/web/js/modules/vector-styles/reducers.js b/web/js/modules/vector-styles/reducers.jsindex 8dd1bd69a..1d3dfe918 100644--- a/web/js/modules/vector-styles/reducers.js+++ b/web/js/modules/vector-styles/reducers.js@@ -1,5 +1,6 @@import { assign as lodashAssign, get as lodashGet } from 'lodash';import {+ CLEAR_VECTORSTYLE,SET_VECTORSTYLE,SET_FILTER_RANGE,LOADED_CUSTOM_VECTORSTYLES@@ -25,6 +26,10 @@ export function vectorStyleReducer(state = defaultVectorStyleState, action) {return lodashAssign({}, state, {[groupName]: action.vectorStyles});+ case CLEAR_VECTORSTYLE:+ return lodashAssign({}, state, {+ [groupName]: action.vectorStyles || {}+ });case SET_VECTORSTYLE:return lodashAssign({}, state, {[groupName]: action.vectorStylesdiff --git a/web/js/modules/vector-styles/selectors.js b/web/js/modules/vector-styles/selectors.jsindex ba39c9831..c4acfeefd 100644--- a/web/js/modules/vector-styles/selectors.js+++ b/web/js/modules/vector-styles/selectors.js@@ -1,8 +1,8 @@import {get as lodashGet,isUndefined as lodashIsUndefined,- each as lodashEach,- cloneDeep as lodashCloneDeep+ each as lodashEach+ // cloneDeep as lodashCloneDeep} from 'lodash';import { getMinValue, getMaxValue } from './util';import update from 'immutability-helper';@@ -73,17 +73,16 @@ export function getCount(layerId, state) {// return false;// }// var rendered = getAllVectorStyles(layerId, index, state);-// if (vectorStyle.type !== 'classification') {-// if (vectorStyle.min <= 0) {-// delete vectorStyle.min;-// }-// if (vectorStyle.max >= rendered.entries.values.length) {-// delete vectorStyle.max;-// }-// if (!lodashIsUndefined(vectorStyle.min) || !lodashIsUndefined(vectorStyle.max)) {-// use = true;-// return false;-// }+// console.log(rendered);+// if (vectorStyle.min <= 0) {+// delete vectorStyle.min;+// }+// if (vectorStyle.max >= rendered.entries.values.length) {+// delete vectorStyle.max;+// }+// if (!lodashIsUndefined(vectorStyle.min) || !lodashIsUndefined(vectorStyle.max)) {+// use = true;+// return false;// }// });// return use;@@ -190,21 +189,23 @@ export function findIndex(layerId, type, value, index, groupStr, state) {});return result;}-export function setCustomSelector(layerId, vectorStyleId, index, groupName, state) {- const { config, vectorStyles } = state;- if (!config.layers[layerId]) {- throw new Error('Invalid layer: ' + layerId);- }- let newVectorStyles = prepare(layerId, vectorStyles[groupName], state);- index = lodashIsUndefined(index) ? 0 : index;- var active = newVectorStyles[layerId];- var vectorStyle = active.maps[index];- if (vectorStyle.custom === vectorStyleId) {- return;- }- vectorStyle.custom = vectorStyleId;- // return updateLookup(layerId, newVectorStyles, state);-}+// export function setCustomSelector(def, vectorStyleId, vectorStyles, layer, state, groupName) {+// const { config } = state;+// if (!config.layers[def.id]) {+// throw new Error('Invalid layer: ' + def.id);+// }+// let newVectorStyles = prepare(def.id, vectorStyles[groupName], state);+// def = lodashIsUndefined(def) ? 0 : def;+// var active = newVectorStyles[def.id];+// var vectorStyle = active.maps[def];+// if (vectorStyle.custom === vectorStyleId) {+// return;+// }+// vectorStyle.custom = vectorStyleId;+// setStyleFunction(def, vectorStyleId, vectorStyles, layer, state);++// return updateLookup(def.id, newVectorStyles, state);+// }export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state) {var styleFunction;@@ -232,7 +233,7 @@ export function setStyleFunction(def, vectorStyleId, vectorStyles, layer, state)}});}- return glStyle;+ return glStyle; // this is wrong}export function getKey(layerId, groupStr, state) {@@ -306,20 +307,51 @@ export function clearCustomSelector(layerId, index, vectorStyles) {}return update(vectorStyles, { layerId: { maps: { $unset: ['custom'] } } }); // remove custom key}-var prepare = function(layerId, vectorStylesObj, state) {- var newVectorStyles = lodashCloneDeep(vectorStylesObj);- if (!newVectorStyles[layerId]) newVectorStyles[layerId] = {};- var active = newVectorStyles[layerId];- active.maps = active.maps || [];- lodashEach(getAllVectorStyles(layerId, undefined, state).maps, function(- vectorStyle,- index- ) {- if (!active.maps[index]) {- newVectorStyles = update(newVectorStyles, {- [layerId]: { maps: { [index]: { $set: vectorStyle } } }- });- }- });- return newVectorStyles;-};++export function clearStyleFunction(def, vectorStyleId, vectorStyles, layer, state) {+ var styleFunction;+ var layerId = def.id;+ var glStyle = vectorStyles[layerId];+ var olMap = lodashGet(state, 'legacy.map.ui.selected');+ if (olMap) {+ lodashEach(olMap.getLayers().getArray(), subLayer => {+ if (subLayer.wv.id === layerId) {+ layer = subLayer;+ }+ });+ }++ styleFunction = stylefunction(layer, glStyle, vectorStyleId);+ if (glStyle.name === 'Orbit Tracks') {+ // Filter time by 5 mins+ layer.setStyle(function(feature, resolution) {+ var minute;+ var minutes = feature.get('label');+ if (minutes) {+ minute = minutes.split(':');+ }+ if ((minute && minute[1] % 5 === 0) || feature.type_ === 'LineString') {+ return styleFunction(feature, resolution);+ }+ });+ }+ return update(vectorStyles, { layerId: { maps: { $unset: ['custom'] } } });+}++// var prepare = function(layerId, vectorStylesObj, state) {+// var newVectorStyles = lodashCloneDeep(vectorStylesObj);+// if (!newVectorStyles[layerId]) newVectorStyles[layerId] = {};+// var active = newVectorStyles[layerId];+// active.maps = active.maps || [];+// lodashEach(getAllVectorStyles(layerId, undefined, state).maps, function(+// vectorStyle,+// index+// ) {+// if (!active.maps[index]) {+// newVectorStyles = update(newVectorStyles, {+// [layerId]: { maps: { [index]: { $set: vectorStyle } } }+// });+// }+// });+// return newVectorStyles;+// };diff --git a/web/js/modules/vector-styles/util.js b/web/js/modules/vector-styles/util.jsindex 515b2a392..6931b32e1 100644--- a/web/js/modules/vector-styles/util.js+++ b/web/js/modules/vector-styles/util.js@@ -49,24 +49,22 @@ export function loadVectorStyles(permlinkState, state) {var min = [];var max = [];var count = 0;- if (layerDef.custom) {- let vectorStyleId = layerDef.custom;- lodashEach(layerDef.custom, function(value, index) {- try {- let newVectorStyles = setStyleFunction(- layerDef,- vectorStyleId,- state.vectorStyles.custom,- stateObj.groupStr,- state- );- state = update(state, {- vectorStyles: { [stateObj.groupStr]: { $set: newVectorStyles } }- });- } catch (error) {- console.warn(' Invalid vectorStyle: ' + value);- }- });+ if (layerDef.custom && layerDef.custom[0]) {+ let vectorStyleId = layerDef.custom[0];+ try {+ let newVectorStyles = setStyleFunction(+ layerDef,+ vectorStyleId,+ state.vectorStyles.custom,+ stateObj.groupStr,+ state+ );+ state = update(state, {+ vectorStyles: { [stateObj.groupStr]: { $set: newVectorStyles } }+ });+ } catch (error) {+ console.warn(' Invalid vectorStyle: ' + vectorStyleId);+ }}if (layerDef.min) {lodashEach(layerDef.min, function(value, index) {