From 33e87b45413081ecead43f3eebce78efc07ef666 Mon Sep 17 00:00:00 2001 From: christof-wittreich Date: Thu, 18 Jul 2024 12:28:01 -0400 Subject: [PATCH] Added getSmallerExtent reusable function --- .../layer/settings/imagery-search.js | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/web/js/components/layer/settings/imagery-search.js b/web/js/components/layer/settings/imagery-search.js index ec45a9351d..7d43f71a6c 100644 --- a/web/js/components/layer/settings/imagery-search.js +++ b/web/js/components/layer/settings/imagery-search.js @@ -37,7 +37,7 @@ export default function ImagerySearch({ layer }) { const conceptID = layer?.conceptIds?.[0]?.value || layer?.collectionConceptID; - const getOlderGranules = async (layer, refDate = selectedDate, pageNum = 1) => { + const getSmallerExtent = () => { // clamp extent to maximum extent allowed by the CMR api const extent = map.extent.map((coord, i) => { const condition = i <= 1 ? coord > maxExtent[i] : coord < maxExtent[i]; @@ -55,6 +55,11 @@ export default function ImagerySearch({ layer }) { extent[2] - (xDiff * 0.2), extent[3] - (yDiff * 0.1), ]; + return smallerExtent; + }; + + const getOlderGranules = async (layer, refDate = selectedDate, pageNum = 1) => { + const smallerExtent = getSmallerExtent(); try { const olderUrl = `https://cmr.earthdata.nasa.gov/search/granules.json?collection_concept_id=${conceptID}&bounding_box=${smallerExtent.join(',')}&temporal=,${refDate.toISOString()}&sort_key=-start_date&pageSize=25&page_num=${pageNum}`; const olderResponse = await fetch(olderUrl, { headers }); @@ -68,23 +73,7 @@ export default function ImagerySearch({ layer }) { }; const getNewerGranules = async (layer, refDate = selectedDate, pageNum = 1) => { - // clamp extent to maximum extent allowed by the CMR api - const extent = map.extent.map((coord, i) => { - const condition = i <= 1 ? coord > maxExtent[i] : coord < maxExtent[i]; - if (condition) { - return coord; - } - return maxExtent[i]; - }); - const xDiff = Math.abs(extent[0] - extent[2]); - const yDiff = Math.abs(extent[1] - extent[3]); - // Reduce width by 40% and height by 20%, to show only centered data - const smallerExtent = [ - extent[0] + (xDiff * 0.2), - extent[1] + (yDiff * 0.1), - extent[2] - (xDiff * 0.2), - extent[3] - (yDiff * 0.1), - ]; + const smallerExtent = getSmallerExtent(); try { const newerUrl = `https://cmr.earthdata.nasa.gov/search/granules.json?collection_concept_id=${conceptID}&bounding_box=${smallerExtent.join(',')}&temporal=${refDate.toISOString()},&sort_key=start_date&pageSize=25&page_num=${pageNum}`; const newerResponse = await fetch(newerUrl, { headers });