Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-3147 update collections when projection changes (#5122)

Patrick Mouldene8aa908a79bc
diff --git a/web/js/containers/sidebar/layer-row.js b/web/js/containers/sidebar/layer-row.js
index b7f31402a..d188edfd8 100644
--- a/web/js/containers/sidebar/layer-row.js
+++ b/web/js/containers/sidebar/layer-row.js
@@ -646,7 +646,7 @@ const makeMapStateToProps = () => {
const dailyDate = formatDailyDate(activeDate);
const selectedDate = date.selected;
const subdailyDate = formatSubdailyDate(activeDate);
- const collections = getCollections(layers, dailyDate, subdailyDate, layer);
+ const collections = getCollections(layers, dailyDate, subdailyDate, layer, proj.id);
const measurementDescriptionPath = getDescriptionPath(state, ownProps);
const { ddvZoomAlerts, ddvLocationAlerts } = state.alerts;
diff --git a/web/js/mapUI/components/update-collections/updateCollections.js b/web/js/mapUI/components/update-collections/updateCollections.js
index 684dc55dd..73cbc106f 100644
--- a/web/js/mapUI/components/update-collections/updateCollections.js
+++ b/web/js/mapUI/components/update-collections/updateCollections.js
@@ -14,6 +14,7 @@ function UpdateCollections () {
const proj = useSelector((state) => state.proj);
const sources = useSelector((state) => state.config.sources);
const layerConfig = useSelector((state) => state.layers.layerConfig);
+ const projId = useSelector((state) => state.proj.id);
// Finds the correct subdomain to query headers from based on the layer source and GIBS/GITC env
const lookupLayerSource = (layerId) => {
@@ -49,7 +50,7 @@ function UpdateCollections () {
if (type !== 'NRT' && type !== 'STD') return undefined;
return {
- id, date: formattedDate, type, version,
+ id, date: formattedDate, type, version, projection: proj.id,
};
} catch (error) {
// errors will clutter console, turn this on for debugging
@@ -59,7 +60,7 @@ function UpdateCollections () {
return undefined;
};
- const findLayerCollections = (layers, dailyDate, subdailyDate) => {
+ const findLayerCollections = (layers, dailyDate, subdailyDate, forceUpdate) => {
const wmtsLayers = layers.filter((layer) => {
if (layer.type !== 'wmts' || !layer.visible) return false;
@@ -70,15 +71,15 @@ function UpdateCollections () {
const collectionDate = layerInCollections.dates.some((d) => d.date === date);
- return !collectionDate; // If date exists in layer collection, don't query layer
+ return !collectionDate || forceUpdate; // If date exists in layer collection, don't query layer
});
return wmtsLayers;
};
- const updateLayerCollections = async () => {
+ const updateLayerCollections = async (forceUpdate = false) => {
const formattedDailyDate = formatDailyDate(selectedDate);
const formattedSubdailyDate = formatSubdailyDate(selectedDate);
- const layersToUpdate = findLayerCollections(layers, formattedDailyDate, formattedSubdailyDate);
+ const layersToUpdate = findLayerCollections(layers, formattedDailyDate, formattedSubdailyDate, forceUpdate);
const headerPromises = layersToUpdate.map((layer) => getHeaders(layer, selectedDate));
try {
@@ -96,6 +97,11 @@ function UpdateCollections () {
updateLayerCollections();
}, [selectedDate, layers]);
+ useEffect(() => {
+ if (!layers.length) return;
+ updateLayerCollections(true);
+ }, [projId]);
+
return null;
}
diff --git a/web/js/modules/layers/reducers.js b/web/js/modules/layers/reducers.js
index e7f01c938..847e9497c 100644
--- a/web/js/modules/layers/reducers.js
+++ b/web/js/modules/layers/reducers.js
@@ -351,14 +351,28 @@ export function layerReducer(state = initialState, action) {
const updates = {};
action.payload.forEach((collection) => {
const {
- id, date, type, version,
+ id, date, type, version, projection,
} = collection;
// If the layer doesn't exist, initialize it
if (!state.collections[id]) {
- updates[id] = { $set: { dates: [{ version, type, date }] } };
+ updates[id] = {
+ $set: {
+ dates: [{
+ version,
+ type,
+ date,
+ projection,
+ }],
+ },
+ };
} else {
// If the layer exists, prepare to push to the dates array
- const newEntry = { date, type, version };
+ const newEntry = {
+ date,
+ type,
+ version,
+ projection,
+ };
updates[id] = {
dates: { $push: [newEntry] },
};
diff --git a/web/js/modules/layers/selectors.js b/web/js/modules/layers/selectors.js
index 51fce8f14..9bf84ed87 100644
--- a/web/js/modules/layers/selectors.js
+++ b/web/js/modules/layers/selectors.js
@@ -126,11 +126,11 @@ export const getStartingLayers = createSelector([getConfig], (config) => resetLa
export const isGroupingEnabled = ({ compare, layers }) => layers[compare.activeString].groupOverlays;
-export const getCollections = (layers, dailyDate, subdailyDate, layer) => {
+export const getCollections = (layers, dailyDate, subdailyDate, layer, projId) => {
if (!layers.collections[layer.id]) return;
const dateCollection = layers.collections[layer.id].dates;
for (let i = 0; i < dateCollection.length; i += 1) {
- if (dateCollection[i].date === dailyDate || dateCollection[i].date === subdailyDate) {
+ if ((dateCollection[i].date === dailyDate || dateCollection[i].date === subdailyDate) && dateCollection[i].projection === projId) {
return dateCollection[i];
}
}