Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Reset the palette, min and max values if these are not present in the current step url but were present in previous step

ZachTRice423510114e0f
diff --git a/web/js/components/tour/modal-tour-in-progress.js b/web/js/components/tour/modal-tour-in-progress.js
index eaba24f43..5414401b8 100644
--- a/web/js/components/tour/modal-tour-in-progress.js
+++ b/web/js/components/tour/modal-tour-in-progress.js
@@ -119,22 +119,23 @@ class ModalInProgress extends React.Component {
currentStepLink = currentStory.steps[currentStepIndex]['stepLink'] +
'&tr=' + this.props.currentStoryId;
- // Get current step transistion
- stepTransition = currentStory.steps[currentStepIndex]['transition'];
+ // Remove base URL from step links string
+ currentStepLink = currentStepLink.split('/?').pop();
// Get previous step link (if there is a previous step)
+ // Remove base URL from step links string
if (prevStepIndex !== null && !isNaN(prevStepIndex)) {
prevStepLink = currentStory.steps[prevStepIndex]['stepLink'];
+ prevStepLink = prevStepLink.split('/?').pop();
}
- // Remove base URL from step links string
- currentStepLink = currentStepLink.split('/?').pop();
- prevStepLink = currentStepLink.split('/?').pop();
-
// Create current and previous states from step links
currentState = util.fromQueryString(currentStepLink);
prevState = util.fromQueryString(prevStepLink);
+ // Get current step transistion
+ stepTransition = currentStory.steps[currentStepIndex]['transition'];
+
// Pass current step query string to the browser url
if (util.browser.history) {
window.history.pushState(
@@ -183,11 +184,37 @@ class ModalInProgress extends React.Component {
parser(prevState, errors, config);
});
- // Reset the palettes
- config.palettes = {
- rendered: {},
- custom: {}
- };
+ // Reset the palette, min and max values if these are not present in the
+ // current step url but were present in previous step.
+ if (prevStepLink) {
+ Object.values(prevState.l).forEach(prevLayer => {
+ if (prevLayer.id) {
+ Object.values(currentState.l).forEach(currentLayer => {
+ if (prevLayer.id === currentLayer.id) {
+ if (!util.objectsHaveSameKeys(prevLayer.attributes, currentLayer.attributes)) {
+ let prevAttrArray = prevLayer.attributes;
+ let currentAttrArray = currentLayer.attributes;
+ if (prevAttrArray.find(prevAttrArray => (prevAttrArray.id === 'palette')) &&
+ !currentAttrArray.find(currentAttrArray => (currentAttrArray.id === 'palette'))) {
+ let array = currentLayer.attributes;
+ array.push({ id: 'palette', value: '' });
+ }
+ if (prevAttrArray.find(prevAttrArray => (prevAttrArray.id === 'min')) &&
+ !currentAttrArray.find(currentAttrArray => (currentAttrArray.id === 'min'))) {
+ let array = currentLayer.attributes;
+ array.push({ id: 'min', value: '' });
+ }
+ if (prevAttrArray.find(prevAttrArray => (prevAttrArray.id === 'max')) &&
+ !currentAttrArray.find(currentAttrArray => (currentAttrArray.id === 'max'))) {
+ let array = currentLayer.attributes;
+ array.push({ id: 'max', value: '' });
+ }
+ }
+ }
+ });
+ }
+ });
+ }
requirements = palettes.requirements(currentState, config);
diff --git a/web/js/palettes/palettes.js b/web/js/palettes/palettes.js
index 11b39bc24..ee3c39319 100644
--- a/web/js/palettes/palettes.js
+++ b/web/js/palettes/palettes.js
@@ -115,10 +115,12 @@ export default (function(self) {
};
self.requirements = function(state, config) {
var promises = [];
- config.palettes = {
- rendered: {},
- custom: {}
- };
+ if (!state.tr) {
+ config.palettes = {
+ rendered: {},
+ custom: {}
+ };
+ }
lodashEach(state.l, function(qsLayer) {
var layerId = qsLayer.id;
if (config.layers[layerId] && config.layers[layerId].palette) {
diff --git a/web/js/util/util.js b/web/js/util/util.js
index fc1b18e4f..f522e899b 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -1170,5 +1170,17 @@ export default (function (self) {
}
};
+ /**
+ * Check if objects have the same keys
+ *
+ * @param {array} comment seperated list of objects
+ * @return {bool}
+ */
+ self.objectsHaveSameKeys = function(...objects) {
+ const allKeys = objects.reduce((keys, object) => keys.concat(Object.keys(object)), []);
+ const union = new Set(allKeys);
+ return objects.every(object => union.size === Object.keys(object).length);
+ };
+
return self;
})({});