Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

add dynamic ab compare dates

Ed Platoe794d174304f
diff --git a/web/js/map/compare/compare.js b/web/js/map/compare/compare.js
index 6bb6b36fa..1832f5e20 100644
--- a/web/js/map/compare/compare.js
+++ b/web/js/map/compare/compare.js
@@ -46,10 +46,9 @@ export default function mapCompare(store) {
});
};
- self.update = function (group) {
- const state = store.getState();
+ self.update = (state, group) => {
if (comparison) {
- comparison.update(state.compare.isCompareA, group);
+ comparison.update(state, group);
}
};
@@ -62,13 +61,13 @@ export default function mapCompare(store) {
const state = store.getState();
if (compareMode === mode && comparison && proj === state.proj.selected && self.value === state.compare.value) {
- comparison.update(state.compare.isCompareA);
+ comparison.update(state);
} else if (comparison) {
mode = compareMode;
self.destroy();
comparison = new self[compareMode](
map,
- state.compare.isCompareA,
+ state,
self.EventTypeObject,
state.compare.value || null,
); // e.g. new self.swipe()
@@ -76,7 +75,7 @@ export default function mapCompare(store) {
mode = compareMode;
comparison = new self[compareMode](
map,
- state.compare.isCompareA,
+ state,
self.EventTypeObject,
state.compare.value || null,
); // e.g. new self.swipe()
diff --git a/web/js/map/compare/spy.js b/web/js/map/compare/spy.js
index ed82df9b3..6c41e08f2 100644
--- a/web/js/map/compare/spy.js
+++ b/web/js/map/compare/spy.js
@@ -8,11 +8,14 @@ const bottomLayers = [];
const DEFAULT_RADIUS = 140;
let radius = DEFAULT_RADIUS;
let label = null;
+// state.compare.isCompareA
+const isCompareA = (state) => state.compare.isCompareA;
export default class Spy {
- constructor(olMap, isBInside) {
+ constructor(olMap, state) {
this.mapCase = document.getElementById('wv-map');
this.map = olMap;
+ const isBInside = isCompareA(state);
this.create(isBInside);
}
diff --git a/web/js/map/compare/swipe.js b/web/js/map/compare/swipe.js
index 9edbfd282..0c4f72d26 100644
--- a/web/js/map/compare/swipe.js
+++ b/web/js/map/compare/swipe.js
@@ -20,25 +20,29 @@ let dragging = false;
export default class Swipe {
constructor(
olMap,
- isActive,
+ state,
eventListenerStringObj,
valueOverride,
) {
listenerObj = eventListenerStringObj;
this.map = olMap;
percentSwipe = valueOverride / 100;
- this.create();
+ this.create(state);
window.addEventListener('resize', () => {
if (document.querySelector('.ab-swipe-line')) {
this.destroy();
- this.create();
+ this.create(state);
}
});
}
- create() {
- line = addLineOverlay(this.map);
- this.update();
+ create(state) {
+ const { date } = state;
+ const { selected, selectedB } = date;
+ this.dateA = util.toISOStringDate(selected);
+ this.dateB = util.toISOStringDate(selectedB);
+ line = addLineOverlay(this.map, this.dateA, this.dateB);
+ this.update(state);
}
getSwipeOffset = () => swipeOffset
@@ -59,15 +63,24 @@ export default class Swipe {
}
}
- update(isCompareA, groupName) {
- const mapLayers = this.map.getLayers().getArray();
- if (!groupName) {
- this.applyEventsToBaseLayers(mapLayers[1], applyLayerListeners);
- this.applyEventsToBaseLayers(mapLayers[0], applyReverseLayerListeners);
- } else if (groupName === 'active') {
- this.applyEventsToBaseLayers(mapLayers[0], applyReverseLayerListeners);
+ update(state, groupName) {
+ const { date } = state;
+ const { selected, selectedB } = date;
+ const dateA = util.toISOStringDate(selected);
+ const dateB = util.toISOStringDate(selectedB);
+ if (dateA !== this.dateA || dateB !== this.dateB) {
+ this.destroy();
+ this.create(state);
} else {
- this.applyEventsToBaseLayers(mapLayers[1], applyLayerListeners);
+ const mapLayers = this.map.getLayers().getArray();
+ if (!groupName) {
+ this.applyEventsToBaseLayers(mapLayers[1], applyLayerListeners);
+ this.applyEventsToBaseLayers(mapLayers[0], applyReverseLayerListeners);
+ } else if (groupName === 'active') {
+ this.applyEventsToBaseLayers(mapLayers[0], applyReverseLayerListeners);
+ } else {
+ this.applyEventsToBaseLayers(mapLayers[1], applyLayerListeners);
+ }
}
}
@@ -134,8 +147,10 @@ export default class Swipe {
/**
* Add Swiper
* @param {Object} map | OL map object
+ * @param {String} dateA | YYYY-MM-DD
+ * @param {String} dateB | YYYY-MM-DD
*/
-const addLineOverlay = function(map) {
+const addLineOverlay = function(map, dateA, dateB) {
const lineCaseEl = document.createElement('div');
const draggerEl = document.createElement('div');
const draggerCircleEl = document.createElement('div');
@@ -146,8 +161,17 @@ const addLineOverlay = function(map) {
draggerCircleEl.className = 'swipe-dragger-circle';
firstLabel.className = 'ab-swipe-span left-label';
secondLabel.className = 'ab-swipe-span right-label';
- firstLabel.appendChild(document.createTextNode('A'));
- secondLabel.appendChild(document.createTextNode('B'));
+ const isSameDate = dateA === dateB;
+ let dateAText = 'A';
+ let dateBText = 'B';
+ if (!isSameDate) {
+ firstLabel.className += ' show-date-label';
+ secondLabel.className += ' show-date-label';
+ dateAText += `: ${dateA}`;
+ dateBText += `: ${dateB}`;
+ }
+ firstLabel.appendChild(document.createTextNode(dateAText));
+ secondLabel.appendChild(document.createTextNode(dateBText));
draggerEl.className = 'ab-swipe-dragger';
lineCaseEl.className = 'ab-swipe-line';
@@ -245,7 +269,7 @@ const applyLayerListeners = function(layer) {
bottomLayers.push(layer);
};
/**
- * Layers need to be inversly clipped so that they can't be seen through
+ * Layers need to be inversely clipped so that they can't be seen through
* the other layergroup in cases where the layergroups layer opacity is < 100%
* @param {Object} layer | Ol Layer object
*/
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index cb4a1f944..812c83c31 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -793,7 +793,7 @@ export default function mapui(models, config, store, ui) {
previousLayer: layerValue ? layerValue.wv : null,
}),
);
- compareMapUi.update(compare.activeString);
+ compareMapUi.update(state);
}
} else {
const index = findLayerIndex(def);