Skip to content

Commit

Permalink
Added getSmallerExtent reusable function
Browse files Browse the repository at this point in the history
  • Loading branch information
christof-wittreich committed Jul 18, 2024
1 parent 2c74d7f commit 33e87b4
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions web/js/components/layer/settings/imagery-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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 });
Expand All @@ -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 });
Expand Down

0 comments on commit 33e87b4

Please sign in to comment.