Skip to content
Snippets Groups Projects
Commit d27671c6 authored by Jacob Cain's avatar Jacob Cain
Browse files

Fetch queriables in initial request

parent 79c94db8
No related branches found
No related tags found
No related merge requests found
...@@ -18,3 +18,6 @@ app/node_modules ...@@ -18,3 +18,6 @@ app/node_modules
.Trashes .Trashes
ehthumbs.db ehthumbs.db
Thumbs.db Thumbs.db
# IDE generated files
.vscode
\ No newline at end of file
...@@ -61,12 +61,8 @@ export default function FootprintResults(props) { ...@@ -61,12 +61,8 @@ export default function FootprintResults(props) {
setCollectionId(newCollectionId); setCollectionId(newCollectionId);
setMatched(featureCollections[newCollectionId].numberMatched); setMatched(featureCollections[newCollectionId].numberMatched);
// Extract the selected collection title
const selectedCollection = props.target.collections.find(collection => collection.id === newCollectionId);
const selectedCollectionTitle = selectedCollection ? selectedCollection.title : '';
// Call the callback function to pass the selected title to the Sidebar // Call the callback function to pass the selected title to the Sidebar
props.updateSelectedTitle(selectedCollectionTitle); props.updateAvailableQueriables(props.target.collections.find(col => col.id === newCollectionId).querTitles);
props.UpdateQueryableTitles(null); props.UpdateQueryableTitles(null);
......
...@@ -147,9 +147,6 @@ export default function SearchAndFilterInput(props) { ...@@ -147,9 +147,6 @@ export default function SearchAndFilterInput(props) {
props.setFilterString(myFilterString); props.setFilterString(myFilterString);
} }
// initialize pyGeoAPI flag
let pyGeoAPIFlag = false;
// New state for queryable titles // New state for queryable titles
const [queryableTitles, setQueryableTitles] = useState([]); const [queryableTitles, setQueryableTitles] = useState([]);
...@@ -160,57 +157,11 @@ export default function SearchAndFilterInput(props) { ...@@ -160,57 +157,11 @@ export default function SearchAndFilterInput(props) {
const isInPyAPI = collection.filter(data => data.hasOwnProperty('itemType')); const isInPyAPI = collection.filter(data => data.hasOwnProperty('itemType'));
// finds and assigns the selected collection from the PYGEO api // finds and assigns the selected collection from the PYGEO api
const selectedCollection = isInPyAPI.find(data => data.title === props.selectedTitle); const selectedCollection = isInPyAPI.find(data => data.title === props.availableQueriables);
// retrieves all pyGEO titles // retrieves all pyGEO titles
const collectionTitles = isInPyAPI.map(data => data.title); const collectionTitles = isInPyAPI.map(data => data.title);
// checks if correct title selected
if (collectionTitles.includes(props.selectedTitle))
{
//set pyGeoAPI flag
pyGeoAPIFlag = true;
// set the selected link
let QueryableDirectoryLink = selectedCollection.links.find(link => link.rel === "queryables").href;
// creates URL to get the properties
let QueryableURL = 'https://astrogeology.usgs.gov/pygeoapi/' + QueryableDirectoryLink;
// fetches URL to get the properties
fetch(QueryableURL)
.then(response => response.json())
.then(data => {
let queryableTitlesArray = [];
// Extract the "properties" property from the JSON response
let Queryables = data.properties;
// loop over titles
for (const property in Queryables) {
if (Queryables.hasOwnProperty(property) && Queryables[property].hasOwnProperty("title")) {
queryableTitlesArray.push(data.properties[property].title);
}
}
// Set the state with the queryable titles
setQueryableTitles(queryableTitlesArray);
}, [])
.catch(error => {
console.error("Error fetching data:", error);
});
}
const [selectedOptions, setSelectedOptions] = useState([]); const [selectedOptions, setSelectedOptions] = useState([]);
const handleOptionChange = event => { const handleOptionChange = event => {
...@@ -326,7 +277,7 @@ export default function SearchAndFilterInput(props) { ...@@ -326,7 +277,7 @@ export default function SearchAndFilterInput(props) {
<Collapse in={expandFilter}> <Collapse in={expandFilter}>
<div className="panelSection panelBar"> <div className="panelSection panelBar">
<span> <span>
<FormControl sx={{ minWidth: 150 }}> <FormControl sx={{ minWidth: 180 }}>
<InputLabel id="sortByLabel" size="small"> <InputLabel id="sortByLabel" size="small">
Sort By Sort By
</InputLabel> </InputLabel>
...@@ -357,23 +308,25 @@ export default function SearchAndFilterInput(props) { ...@@ -357,23 +308,25 @@ export default function SearchAndFilterInput(props) {
</span> </span>
</div> </div>
{pyGeoAPIFlag && ( {props.availableQueriables.length > 0 && (
<>
<Divider/>
<div className="panelSection panelBar"> <div className="panelSection panelBar">
<span> <span>
<FormControl sx={{ minWidth: 150 , minHeight: 40}}> <FormControl sx={{ minWidth: 180 , minHeight: 40}}>
<InputLabel id="selectQueryLabel" size="small" style={{paddingTop: '0.2rem'}}> <InputLabel id="showPropertiesLabel" size="small" style={{paddingTop: '0.2rem'}}>
Show Properties Show Properties
</InputLabel> </InputLabel>
<Select <Select
labelId="selectQueryLabel" labelId="showPropertiesLabel"
label="Select Query" label="Show Properties"
multiple multiple
value={selectedOptions} value={selectedOptions}
onChange={handleOptionChange} onChange={handleOptionChange}
renderValue={(selected) => selected.join(', ')} renderValue={(selected) => selected.join(', ')}
style={{height: 43}} style={{height: 43}}
> >
{queryableTitles.map((title) => ( {props.availableQueriables.map((title) => (
<MenuItem key={title} value={title}> <MenuItem key={title} value={title}>
<Checkbox checked={selectedOptions.includes(title)} /> <Checkbox checked={selectedOptions.includes(title)} />
<ListItemText primary={title} /> <ListItemText primary={title} />
...@@ -383,6 +336,7 @@ export default function SearchAndFilterInput(props) { ...@@ -383,6 +336,7 @@ export default function SearchAndFilterInput(props) {
</FormControl> </FormControl>
</span> </span>
</div> </div>
</>
)} )}
<Divider/> <Divider/>
......
...@@ -44,11 +44,12 @@ export default function Sidebar(props) { ...@@ -44,11 +44,12 @@ export default function Sidebar(props) {
}; };
// State to hold the selected title // State to hold the selected title
const [selectedTitle, setSelectedTitle] = React.useState(""); const [availableQueriables, setAvailableQueriables] = React.useState("");
// Callback function to update selected title // Callback function to update selected title
const updateSelectedTitle = (newTitle) => { const updateAvailableQueriables = (queriables) => {
setSelectedTitle(newTitle); console.log(queriables);
setAvailableQueriables(queriables);
}; };
// State to hold the seleced queryables // State to hold the seleced queryables
...@@ -72,7 +73,7 @@ export default function Sidebar(props) { ...@@ -72,7 +73,7 @@ export default function Sidebar(props) {
setFilterString={setFilterString} setFilterString={setFilterString}
targetName={props.target.name} targetName={props.target.name}
target={props.target} target={props.target}
selectedTitle={selectedTitle} availableQueriables={availableQueriables}
UpdateQueryableTitles = {UpdateQueryableTitles} UpdateQueryableTitles = {UpdateQueryableTitles}
/> />
<FootprintResults <FootprintResults
...@@ -80,7 +81,7 @@ export default function Sidebar(props) { ...@@ -80,7 +81,7 @@ export default function Sidebar(props) {
filterString={filterString} filterString={filterString}
queryAddress={props.queryAddress} queryAddress={props.queryAddress}
setQueryAddress={props.setQueryAddress} setQueryAddress={props.setQueryAddress}
updateSelectedTitle={updateSelectedTitle} updateAvailableQueriables={updateAvailableQueriables}
selectedQueryables = {updatedQueryableTitles} selectedQueryables = {updatedQueryableTitles}
UpdateQueryableTitles = {UpdateQueryableTitles} UpdateQueryableTitles = {UpdateQueryableTitles}
/> />
......
...@@ -65,7 +65,7 @@ export default async function Initialize(){ ...@@ -65,7 +65,7 @@ export default async function Initialize(){
} }
// Combine data from Astro Web Maps and STAC API into one new object // Combine data from Astro Web Maps and STAC API into one new object
function organizeData(astroWebMaps, stacApiCollections, vectorApiCollections) { async function organizeData(astroWebMaps, stacApiCollections, vectorApiCollections) {
// Initialize Objects // Initialize Objects
let mapList = { "systems" : [] }; let mapList = { "systems" : [] };
...@@ -97,6 +97,8 @@ export default async function Initialize(){ ...@@ -97,6 +97,8 @@ export default async function Initialize(){
let sysIndex = mapList.systems.map(sys => sys.name).indexOf(target.system); let sysIndex = mapList.systems.map(sys => sys.name).indexOf(target.system);
// ID the system. This seems to get the main planet of the system. // ID the system. This seems to get the main planet of the system.
// https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/naif_ids.html
// "A planet is always considered to be the 99th satellite of its own barycenter"
if (target.naif % 100 === 99){ if (target.naif % 100 === 99){
mapList.systems[sysIndex].naif = target.naif; mapList.systems[sysIndex].naif = target.naif;
} }
...@@ -113,7 +115,9 @@ export default async function Initialize(){ ...@@ -113,7 +115,9 @@ export default async function Initialize(){
for (const collection of stacApiCollections.collections){ for (const collection of stacApiCollections.collections){
if (target.name == collection.summaries["ssys:targets"][0].toUpperCase()) { if (target.name == collection.summaries["ssys:targets"][0].toUpperCase()) {
// Add a specification to the title in order to show what kind of data the user is requesting // Add a specification to the title in order to show what kind of data the user is requesting
collection.title = collection.title.concat(" (Raster)") collection.dataType = "raster";
collection.querTitles = [];
collection.title = collection.title.concat(" (Raster)");
myCollections.push(collection); myCollections.push(collection);
} }
} }
...@@ -122,8 +126,33 @@ export default async function Initialize(){ ...@@ -122,8 +126,33 @@ export default async function Initialize(){
// view the collection as GEOJSON // view the collection as GEOJSON
let target_name = pycollection.id.split('/')[0]; let target_name = pycollection.id.split('/')[0];
if (target.name == target_name.toUpperCase()) { if (target.name == target_name.toUpperCase()) {
// Set links GeoSTAC needs later
pycollection.links.find(link => link.rel === "items").href = "https://astrogeology.usgs.gov/pygeoapi" + pycollection.links.find(link => link.rel === "items").href; pycollection.links.find(link => link.rel === "items").href = "https://astrogeology.usgs.gov/pygeoapi" + pycollection.links.find(link => link.rel === "items").href;
pycollection.itemsLink = "https://astrogeology.usgs.gov/pygeoapi" + pycollection.links.find(link => link.rel === "items").href;
pycollection.queryablesLink = "https://astrogeology.usgs.gov/pygeoapi" + pycollection.links.find(link => link.rel === "queryables").href;
// Fetch and await queriables
fetchStatus[pycollection.queryablesLink] = "Not Started";
fetchPromise[pycollection.queryablesLink] = "Not Started";
jsonPromise[pycollection.queryablesLink] = "Not Started";
mapsJson[pycollection.queryablesLink] = [];
ensureFetched(pycollection.queryablesLink);
await ensureFetched(pycollection.queryablesLink);
// put queryable titles in array
let querData = mapsJson[pycollection.queryablesLink];
let querTitles = [];
let querProps = querData.properties;
for (const property in querProps) {
if (querProps.hasOwnProperty(property) && querProps[property].hasOwnProperty("title")) {
querTitles.push(querData.properties[property].title);
}
}
// Add a specification to the title in order to show what kind of data the user is requesting // Add a specification to the title in order to show what kind of data the user is requesting
pycollection.dataType = "vector";
pycollection.querTitles = querTitles;
pycollection.title = pycollection.title.concat(" (Vector)"); pycollection.title = pycollection.title.concat(" (Vector)");
myCollections.push(pycollection); myCollections.push(pycollection);
} }
...@@ -228,7 +257,9 @@ export default async function Initialize(){ ...@@ -228,7 +257,9 @@ export default async function Initialize(){
await ensureFetched(stacApiCollections); await ensureFetched(stacApiCollections);
await ensureFetched(vectorApiCollections); await ensureFetched(vectorApiCollections);
return organizeData(mapsJson[astroWebMaps], mapsJson[stacApiCollections], mapsJson[vectorApiCollections]); let organizedData = await organizeData(mapsJson[astroWebMaps], mapsJson[stacApiCollections], mapsJson[vectorApiCollections]);
return organizedData;
} }
aggregateMapList = await getStacAndAstroWebMapsData(); aggregateMapList = await getStacAndAstroWebMapsData();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment