Commit 707f1b74 authored by Jacob Cain's avatar Jacob Cain
Browse files

Sort Systems/bodies on load, add STAC maps

parent 9069648d
Loading
Loading
Loading
Loading
+92 −20
Original line number Diff line number Diff line
@@ -30,15 +30,15 @@ export default function App() {
        "https://stac.astrogeology.usgs.gov/api/collections";

    // Async tracking
    let fetchStatus = {}
    let fetchPromise = {}
    let jsonPromise = {}
    let fetchStatus = {};
    let fetchPromise = {};
    let jsonPromise = {};

    // Fetched Maps
    var mapsJson = {}
    var mapsJson = {};

    // Combined Data
    var aggregateMapList = {}
    var aggregateMapList = {};

    // Init
    fetchStatus[astroWebMaps] = "Not Started";
@@ -55,14 +55,14 @@ export default function App() {
    async function ensureFetched(targetUrl) {
        if(fetchStatus[targetUrl] === "Not Started")
        {
            fetchStatus[targetUrl] = "Started"
            fetchStatus[targetUrl] = "Started";
            fetchPromise[targetUrl] = fetch(
              targetUrl
            ).then((res)=>{
                jsonPromise[targetUrl] = res.json().then((jsonData)=>{
                    mapsJson[targetUrl] = jsonData;
                }).catch((err)=>{
                    console.log(err)
                    console.log(err);
                });
            }).catch((err) => {
                console.log(err);
@@ -81,20 +81,20 @@ export default function App() {

        // Check for Planets that have STAC footprints from the STAC API
        for (let i = 0; i < stacApiCollections.collections.length; i++) {
            if (stacApiCollections.collections[i].hasOwnProperty("summaries")){
            let stacTarget = stacApiCollections.collections[i].summaries["ssys:targets"][0].toLowerCase();
            if(!stacList.find(targetBody => targetBody == stacTarget)){
                stacList.push(stacTarget.toLowerCase());
            }
        }
        }

        // Scan through every target in the Astro Web Maps JSON
        for (const target of astroWebMaps.targets){

            // Check for/add system
            // Check for, add system if system is not in array
            if (!mapList.systems.some(system => system.name === target.system)) {
                mapList.systems.push({
                    "name" : target.system,
                    "naif" : 0,
                    "bodies" : []
                })
            }
@@ -102,28 +102,100 @@ export default function App() {
            // Index of System
            let sysIndex = mapList.systems.map(sys => sys.name).indexOf(target.system);

            // Check for/add body
            // ID the system
            if (target.naif % 100 === 99){
                mapList.systems[sysIndex].naif = target.naif;
            }

            // Check for/add body if not already incl
            if (!mapList.systems[sysIndex].bodies.some(body => body.name === target.name)) {

                // A flag that indicates whether or not the body has footprints
                let hasFootprints = stacList.includes(target.name.toLowerCase())

                // Add STAC collections
                let myCollections = []
                if (hasFootprints) {
                    for (const collection of stacApiCollections.collections){
                        if (target.name == collection.summaries["ssys:targets"][0].toUpperCase()) {
                            myCollections.push(collection);
                        }
                    }
                }

                // Add a body data entry
                mapList.systems[sysIndex].bodies.push({
                    "name" : target.name,
                    "has-footprints" : hasFootprints,
                    "maps" : []
                    "naif" : target.naif,
                    "hasFootprints" : hasFootprints,
                    "layers" : {
                        "base" : [],
                        "overlays" : []
                    },
                    "collections" : myCollections
                })
            }

            // Index of Body
            let bodIndex = mapList.systems[sysIndex].bodies.map(bod => bod.name).indexOf(target.name);

            // Sort through AstroWebMaps to get the right ones for GeoSTAC
            function getWmsMaps(webMaps) {
                let myLayers = {
                    "base" : [],
                    "overlays" : [],
                    /* "wfs" : [] */
                };

                // Add maps
            for (const wmap of target.webmap) {
                mapList.systems[sysIndex].bodies[bodIndex].maps.push(wmap.displayname);
                // More properties?
                for (const wmap of webMaps) {
                    if(wmap.type === "WMS" && wmap.layer != "GENERIC") {
                        if(wmap.transparent == "false") {
                            // Non-transparent layers are base maps
                            myLayers.base.push(wmap);
                        } else if (wmap.displayname != "Show Feature Names"){
                            // Transparent layers are overlays
                            myLayers.overlays.push(wmap);
                        }
                    }
                    // else if (wmap.type === "WFS") {
                    //     // Currently in AstroMap but doesn't seem to be used.
                    //     myLayers.wfs.push(wmap);
                    // }
                }
                return myLayers;
            }

            // Add base and overlay maps (but not empty arrays!)
            let myLayers = getWmsMaps(target.webmap);
            if (myLayers.base.length > 0){
                mapList.systems[sysIndex].bodies[bodIndex].layers.base.push(...myLayers.base);
            }
            if (myLayers.overlays.length > 0){
                mapList.systems[sysIndex].bodies[bodIndex].layers.overlays.push(...myLayers.overlays);
            }
        }

        // Sort systems by NAIF ID
        mapList.systems.sort((a, b)=>{return a.naif - b.naif})

        // Go through each System
        for (let sysIndex = 0; sysIndex < mapList.systems.length; sysIndex++){

            // Remove bodies with no base maps
            for (let bodIndex = mapList.systems[sysIndex].bodies.length - 1; bodIndex >= 0; bodIndex--){
                if(mapList.systems[sysIndex].bodies[bodIndex].layers.base.length < 1){
                    mapList.systems[sysIndex].bodies.splice(bodIndex, 1);
                }
            }
            // Sort targets by naif id
            mapList.systems[sysIndex].bodies.sort((a, b)=>{
                let valA = a.naif;
                let valB = b.naif;
                if (a.naif % 100 == 99) valA = 0; // Planet IDs end with 99,
                if (b.naif % 100 == 99) valB = 0; // but put them first.
                return valA - valB;
            })
        }

        return mapList;
+19 −9
Original line number Diff line number Diff line
@@ -17,11 +17,18 @@ import { blue } from "@mui/material/colors";

// Icons
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
import ScatterPlotIcon from '@mui/icons-material/ScatterPlot';
import PublicIcon from "@mui/icons-material/Public";
import DarkModeIcon from "@mui/icons-material/DarkMode";
import ScatterPlotIcon from '@mui/icons-material/ScatterPlot'; // Systems
import PublicIcon from "@mui/icons-material/Public"; // Planets
import DarkModeIcon from "@mui/icons-material/DarkMode"; // Moons
import CookieIcon from '@mui/icons-material/Cookie'; // Asteroids
import TravelExploreIcon from '@mui/icons-material/TravelExplore'; // Footprints.
// import PetsIcon from '@mui/icons-material/Pets';                 // Other
// import SatelliteAltIcon from '@mui/icons-material/SatelliteAlt'; // possible
// import ViewTimelineIcon from '@mui/icons-material/ViewTimeline'; // footprint
// import WhereToVoteIcon from '@mui/icons-material/WhereToVote';   // icons.
import ExpandLess from '@mui/icons-material/ExpandLess';
import ExpandMore from '@mui/icons-material/ExpandMore';
import { textTransform } from "@mui/system";

/**
 * Controls css styling for this component using js to css
@@ -49,7 +56,7 @@ let css = {

// Delete if new data loading works
// Unless we add images here
// Why is Puck not on this list?
// Why is Puck/Titania not on this list?

const planets = [
  ["Mercury"],
@@ -116,8 +123,8 @@ function PlanetDialog(props) {
  console.log(props.mapList)

  return (
    <Dialog onClose={handleClose} open={open}>
      <DialogTitle>Select Target Body</DialogTitle>
    <Dialog PaperProps={{sx: {overflowY: "scroll"}}} onClose={handleClose} open={open}>
      <DialogTitle sx={{ minWidth: 225 }}>Select Target Body</DialogTitle>
      <List sx={{ pt: 0 }}>
        <ListSubheader value="None">Systems</ListSubheader>
        {props.mapList.systems.map((system, sysIndex) => (
@@ -131,7 +138,9 @@ function PlanetDialog(props) {
                  <ScatterPlotIcon />
                </Avatar>
              </ListItemAvatar>
              <ListItemText primary={system.name} />
              <ListItemText sx={{ textTransform: "capitalize"}} primary={system.name.toLowerCase()} />
              {props.mapList.systems[sysIndex].bodies.map(bod => bod.hasFootprints).includes(true) ? <TravelExploreIcon/> : null}
              {openSys[sysIndex] ? <ExpandLess /> : <ExpandMore />}
            </ListItemButton>
            <Collapse in={openSys[sysIndex]} timeout="auto" unmountOnExit>
              <List component="div" disablePadding>
@@ -143,10 +152,11 @@ function PlanetDialog(props) {
                  >
                    <ListItemAvatar>
                      <Avatar sx={{ bgcolor: blue[100] }}>
                        {body.name === system.name ? <PublicIcon /> : <DarkModeIcon/>}
                        {system.name === "ASTEROIDS" ? <CookieIcon/> : body.name === system.name ? <PublicIcon /> : <DarkModeIcon/>}
                      </Avatar>
                    </ListItemAvatar>
                    <ListItemText primary={body.name} />
                    <ListItemText sx={{textTransform: "capitalize"}} primary={body.name.toLowerCase()} secondary={"Maps: " + body.layers.base.length} />
                    {body.hasFootprints ? <TravelExploreIcon/> : null}
                  </ListItemButton>
                ))}
              </List>