Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

WV-2981: Dynamically update subdomains for collection updates feature for GITC deployments (#4886)

Ryan Weiler0112037dd2d0
diff --git a/web/js/mapUI/components/dev-test-mode/dev-console-test.js b/web/js/mapUI/components/dev-test-mode/dev-console-test.js
index 9b0fdcc28..1d61179c2 100644
--- a/web/js/mapUI/components/dev-test-mode/dev-console-test.js
+++ b/web/js/mapUI/components/dev-test-mode/dev-console-test.js
@@ -6,11 +6,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
function ConsoleTest () {
// eslint-disable-next-line no-unused-vars
const dispatch = useDispatch();
- const {
- map,
- } = useSelector((state) => ({
- map: state.map.ui.selected,
- }));
+ const map = useSelector((state) => state.map.ui.selected);
const consoleResponse = () => {
console.log(map);
diff --git a/web/js/mapUI/components/update-collections/updateCollections.js b/web/js/mapUI/components/update-collections/updateCollections.js
index a6d0788f8..8966ac268 100644
--- a/web/js/mapUI/components/update-collections/updateCollections.js
+++ b/web/js/mapUI/components/update-collections/updateCollections.js
@@ -12,50 +12,49 @@ function UpdateCollections () {
const layers = useSelector((state) => state.layers.active.layers);
const selectedDate = useSelector((state) => getSelectedDate(state));
const proj = useSelector((state) => state.proj);
+ const sources = useSelector((state) => state.config.sources);
+ const layerConfig = useSelector((state) => state.layers.layerConfig);
+
+ // Finds the correct subdomain to query headers from based on the layer source and GIBS/GITC env
+ const lookupLayerSource = (layerId) => {
+ const { source } = layerConfig[layerId].projections[proj.id];
+ const subRegex = /-{[a-z]{1}-[a-z]{1}}/i;
+ const sourceDomain = sources[source].url.replace(subRegex, '-a');
+
+ return sourceDomain;
+ };
const getHeaders = async (def, date) => {
const { id, period } = def;
const { matrixSet } = def.projections[proj.id];
- const crs = `epsg${proj.selected.epsg}`;
const isoStringDate = util.toISOStringSeconds(util.roundTimeOneMinute(selectedDate));
const imageType = def.format === 'image/png' ? 'png' : 'jpeg';
- const srcs = [
- `https://gibs-a.earthdata.nasa.gov/wmts/${crs}/best/wmts.cgi?TIME=${isoStringDate}&layer=${id}&style=default&tilematrixset=${matrixSet}&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2F${imageType}&TileMatrix=0&TileCol=0&TileRow=0`,
- `https://gibs-b.earthdata.nasa.gov/wmts/${crs}/best/wmts.cgi?TIME=${isoStringDate}&layer=${id}&style=default&tilematrixset=${matrixSet}&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2F${imageType}&TileMatrix=0&TileCol=0&TileRow=0`,
- `https://gibs-c.earthdata.nasa.gov/wmts/${crs}/best/wmts.cgi?TIME=${isoStringDate}&layer=${id}&style=default&tilematrixset=${matrixSet}&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2F${imageType}&TileMatrix=0&TileCol=0&TileRow=0`,
- ];
-
- // eslint-disable-next-line no-restricted-syntax
- for (const src of srcs) {
- try {
- // eslint-disable-next-line no-await-in-loop
- const response = await fetch(src);
- if (!response.ok) {
- // If the response is not OK (e.g., 400 error), continue to the next URL
- // eslint-disable-next-line no-continue
- continue;
- }
-
- const { headers } = response;
- const actualId = headers.get('layer-identifier-actual');
- if (!actualId) return undefined;
-
- const parts = actualId.split('_');
- const type = parts[parts.length - 1];
- const version = parts[parts.length - 2];
- const formattedDate = period === 'daily' ? formatDailyDate(date) : formatSubdailyDate(date);
-
- if (type !== 'NRT' && type !== 'STD') return undefined;
-
- return {
- id, date: formattedDate, type, version,
- };
- } catch (error) {
- console.error(error);
- }
+ const sourceDomain = lookupLayerSource(id);
+
+ const sourceUrl = `${sourceDomain}?TIME=${isoStringDate}&layer=${id}&style=default&tilematrixset=${matrixSet}&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2F${imageType}&TileMatrix=0&TileCol=0&TileRow=0`;
+ try {
+ const response = await fetch(sourceUrl);
+
+ const { headers } = response;
+ const actualId = headers.get('layer-identifier-actual');
+ if (!actualId) return undefined;
+
+ const parts = actualId.split('_');
+ const type = parts[parts.length - 1];
+ const version = parts[parts.length - 2];
+ const formattedDate = period === 'daily' ? formatDailyDate(date) : formatSubdailyDate(date);
+
+ if (type !== 'NRT' && type !== 'STD') return undefined;
+
+ return {
+ id, date: formattedDate, type, version,
+ };
+ } catch (error) {
+ // errors will clutter console, turn this on for debugging
+ // console.error(error);
}
- // Return undefined if all srcs fail
+ // Return undefined if query fails
return undefined;
};
@@ -86,7 +85,8 @@ function UpdateCollections () {
const validCollections = results.filter((result) => result !== undefined);
updateCollection(validCollections);
} catch (error) {
- console.error('error', error);
+ // errors will clutter console, turn this on for debugging
+ // console.error(error);
}
};
diff --git a/web/js/mapUI/mapUI.js b/web/js/mapUI/mapUI.js
index fd4961dbe..257fdaf09 100644
--- a/web/js/mapUI/mapUI.js
+++ b/web/js/mapUI/mapUI.js
@@ -101,7 +101,7 @@ function MapUI(props) {
const [preloadAction, setPreloadAction] = useState({});
// eslint-disable-next-line no-unused-vars
- const [tileImageTestMode, setTileImageTestMode] = useState(false);
+ const [devTestMode, setDevTestMode] = useState(false);
const subscribeToStore = function(action) {
switch (action.type) {
@@ -416,7 +416,7 @@ function MapUI(props) {
{ (isTravelModeActive && !isStaticMapActive) && <TravelMode /> }
</>
)}
- {tileImageTestMode && <DevTestButton />}
+ {devTestMode && <DevTestButton />}
</>
);