Skip to content

Commit

Permalink
Use renders from stac
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Aug 6, 2024
1 parent 4591e79 commit 52ecf7a
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
UseQueryResult
} from '@tanstack/react-query';
import axios from 'axios';
import { CollecticonShrinkToLeft } from '@devseed-ui/collecticons';
import {
StacDatasetData,
TimeDensity,
Expand All @@ -22,6 +23,17 @@ function didDataChange(curr: UseQueryResult, prev?: UseQueryResult) {
return prevKey !== currKey;
}


// function formatRenderValuesToParams(renderObj) {
// return Object.keys(renderObj).reduce((acc, curr) => {
// const value = renderObj[curr];
// if (value.constructor === Array && value.length > 0) {
// acc[curr] = value[0];
// } else acc[curr] = value;
// return acc;
// }, {});
// }

/**
* Merges STAC metadata with local dataset, computing the domain.
*
Expand All @@ -43,12 +55,15 @@ function reconcileQueryDataWithDataset(

if (queryData.status === DatasetStatus.SUCCESS) {
const domain = resolveLayerTemporalExtent(base.data.id, queryData.data);
const titilerParams = queryData.data.renderParams?? base.data.sourceParams;

base = {
...base,
data: {
...base.data,
...queryData.data,
domain
domain,
sourceParams: titilerParams
}
};
}
Expand Down Expand Up @@ -77,7 +92,6 @@ async function fetchStacDatasetById(
const { data } = await axios.get(
`${stacApiEndpointToUse}/collections/${stacCol}`
);

const commonTimeseriesParams = {
isPeriodic: !!data['dashboard:is_periodic'],
timeDensity: data['dashboard:time_density'] || TimeDensity.DAY
Expand Down Expand Up @@ -112,13 +126,15 @@ async function fetchStacDatasetById(
? data.summaries.datetime
: data.extent.temporal.interval[0];

const renderParams = data.renders?.dashboard;
if (!domain?.length || domain.some((d) => !d)) {
throw new Error('Invalid datetime domain');
}

return {
...commonTimeseriesParams,
domain
domain,
renderParams
};
}
}
Expand Down

0 comments on commit 52ecf7a

Please sign in to comment.