Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WV-3220 Smaller Extent BBox For Finding High-Resolution Imagery #5347

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 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 @@ -46,8 +46,22 @@ export default function ImagerySearch({ layer }) {
}
return maxExtent[i];
});
const xDiff = Math.abs(extent[0] - extent[2]);
christof-wittreich marked this conversation as resolved.
Show resolved Hide resolved
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),
];
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=${extent.join(',')}&temporal=,${refDate.toISOString()}&sort_key=-start_date&pageSize=25&page_num=${pageNum}`;
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 });
const olderGranules = await olderResponse.json();
const olderDates = olderGranules.feed.entry.map(parseGranuleTimestamp);
Expand All @@ -59,16 +73,9 @@ 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 smallerExtent = getSmallerExtent();
try {
const newerUrl = `https://cmr.earthdata.nasa.gov/search/granules.json?collection_concept_id=${conceptID}&bounding_box=${extent.join(',')}&temporal=${refDate.toISOString()},&sort_key=start_date&pageSize=25&page_num=${pageNum}`;
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 });
const newerGranules = await newerResponse.json();
const newerDates = newerGranules.feed.entry.map(parseGranuleTimestamp);
Expand Down
Loading