Commit 2aa59a59 authored by zksx's avatar zksx
Browse files

got pygeo footprints to display

parent d6e41fe9
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -13,11 +13,12 @@ import Sidebar from "../presentational/Sidebar.jsx";
 * @component
 * @component
 */
 */
export default function GeoStacApp(props) {
export default function GeoStacApp(props) {
  const [targetPlanet, setTargetPlanet] = React.useState(props.mapList.systems[4].bodies[0]);
  let [targetPlanet, setTargetPlanet] = React.useState(props.mapList.systems[4].bodies[0]);

  // make sure its a stac item for appending stuff
  let [queryAddress, setQueryAddress] = React.useState(
    props.mapList.systems[4].bodies[0].collections[0].links.find(link => link.rel === "items").href + "?");


  const [queryAddress, setQueryAddress] = React.useState(
    props.mapList.systems[4].bodies[0].collections[0].links.find(link => link.rel === "items").href + "?"
  );


  /**
  /**
   * Handles target body selection
   * Handles target body selection
+15 −3
Original line number Original line Diff line number Diff line
@@ -113,9 +113,21 @@ export default function FootprintResults(props) {


      let collectionUrls = {};
      let collectionUrls = {};
      for (const collection of props.target.collections) {
      for (const collection of props.target.collections) {

        let isInStacAPI = collection.hasOwnProperty("stac_version");

        if(isInStacAPI)
        {
          let itemsUrl = collection.links.find(link => link.rel === "items").href;
          let itemsUrl = collection.links.find(link => link.rel === "items").href;
          collectionUrls[collection.id] = itemsUrl + myFilter + pageInfo;
          collectionUrls[collection.id] = itemsUrl + myFilter + pageInfo;
        }
        }
        else
        {
          let itemsUrl = collection.links.find(link => link.rel === "items").href;
          collectionUrls[collection.id] = itemsUrl + pageInfo;
        }

      }


      (async () => {
      (async () => {
        let collections = await FetchObjects(collectionUrls);
        let collections = await FetchObjects(collectionUrls);
+2 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ export default L.Map.AstroMap = L.Map.extend({
  },
  },


  initialize: function(mapDiv, target, jsonMaps, options) {
  initialize: function(mapDiv, target, jsonMaps, options) {

    this._mapDiv = mapDiv;
    this._mapDiv = mapDiv;
    this._target = target;
    this._target = target;
    this._jsonMaps = jsonMaps;
    this._jsonMaps = jsonMaps;
@@ -272,6 +273,7 @@ export default L.Map.AstroMap = L.Map.extend({


          this._geoLayers[i].on({click: this.handleClick});  // Add click listener
          this._geoLayers[i].on({click: this.handleClick});  // Add click listener
          
          

          // Add layers to map if they should be visible
          // Add layers to map if they should be visible
          if(featureCollections[i].id === visibleCollectionId) { 
          if(featureCollections[i].id === visibleCollectionId) { 
            this._geoLayers[i].addTo(this);
            this._geoLayers[i].addTo(this);
+27 −5
Original line number Original line Diff line number Diff line
@@ -13,6 +13,9 @@ export default async function Initialize(){
    const stacApiCollections = 
    const stacApiCollections = 
        "https://stac.astrogeology.usgs.gov/api/collections";
        "https://stac.astrogeology.usgs.gov/api/collections";


    const pygeoApiCollections = 
        "https://astrogeology.usgs.gov/pygeoapi/collections";

    // Async tracking
    // Async tracking
    let fetchStatus = {};
    let fetchStatus = {};
    let fetchPromise = {};
    let fetchPromise = {};
@@ -35,6 +38,11 @@ export default async function Initialize(){
    jsonPromise[stacApiCollections] = "Not Started";
    jsonPromise[stacApiCollections] = "Not Started";
    mapsJson[stacApiCollections] = [];
    mapsJson[stacApiCollections] = [];


    fetchStatus[pygeoApiCollections] = "Not Started";
    fetchPromise[pygeoApiCollections] = "Not Started";
    jsonPromise[pygeoApiCollections] = "Not Started";
    mapsJson[pygeoApiCollections] = [];

    // Fetch JSON and read into object
    // Fetch JSON and read into object
    async function ensureFetched(targetUrl) {
    async function ensureFetched(targetUrl) {
        if(fetchStatus[targetUrl] === "Not Started")
        if(fetchStatus[targetUrl] === "Not Started")
@@ -57,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) {
    function organizeData(astroWebMaps, stacApiCollections, pygeoApiCollections) {
        
        
        // Initialize Objects
        // Initialize Objects
        let mapList = { "systems" : [] };
        let mapList = { "systems" : [] };
@@ -66,6 +74,8 @@ export default async function Initialize(){
        // Check for Planets that have STAC footprints from the STAC API
        // Check for Planets that have STAC footprints from the STAC API
        for (let i = 0; i < stacApiCollections.collections.length; i++) {
        for (let i = 0; i < stacApiCollections.collections.length; i++) {
            let stacTarget = stacApiCollections.collections[i].summaries["ssys:targets"][0].toLowerCase();
            let stacTarget = stacApiCollections.collections[i].summaries["ssys:targets"][0].toLowerCase();

            // pushes stacTarget onto the stacList if the target isn't already in the list
            if(!stacList.find(targetBody => targetBody == stacTarget)){
            if(!stacList.find(targetBody => targetBody == stacTarget)){
                stacList.push(stacTarget.toLowerCase());
                stacList.push(stacTarget.toLowerCase());
            }
            }
@@ -86,7 +96,7 @@ export default async function Initialize(){
            // Index of System
            // Index of System
            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
            // ID the system. This seems to get the main planet of the system.
            if (target.naif % 100 === 99){
            if (target.naif % 100 === 99){
                mapList.systems[sysIndex].naif = target.naif;
                mapList.systems[sysIndex].naif = target.naif;
            }
            }
@@ -105,6 +115,16 @@ export default async function Initialize(){
                            myCollections.push(collection);
                            myCollections.push(collection);
                        }
                        }
                    }
                    }
                    for (const pycollection of pygeoApiCollections.collections){

                        // view the collection as GEOJSON
                        let target_name = pycollection.id.split('/')[0];

                        if (target.name == target_name.toUpperCase()) {
                            pycollection.links[9].href = "https://astrogeology.usgs.gov/pygeoapi" + pycollection.links[9].href;
                            myCollections.push(pycollection);
                        }
                    }
                }
                }


                // Add a body data entry
                // Add a body data entry
@@ -198,12 +218,14 @@ export default async function Initialize(){
        // Start fetching from AWM and STAC API concurrently
        // Start fetching from AWM and STAC API concurrently
        ensureFetched(astroWebMaps);
        ensureFetched(astroWebMaps);
        ensureFetched(stacApiCollections);
        ensureFetched(stacApiCollections);
        ensureFetched(pygeoApiCollections);


        // Wait for both to complete before moving on
        // Wait for both to complete before moving on
        await ensureFetched(astroWebMaps);
        await ensureFetched(astroWebMaps);
        await ensureFetched(stacApiCollections);
        await ensureFetched(stacApiCollections);
        await ensureFetched(pygeoApiCollections);


        return organizeData(mapsJson[astroWebMaps], mapsJson[stacApiCollections]);
        return organizeData(mapsJson[astroWebMaps], mapsJson[stacApiCollections], mapsJson[pygeoApiCollections]);
    }
    }


    aggregateMapList = await getStacAndAstroWebMapsData();
    aggregateMapList = await getStacAndAstroWebMapsData();
+2 −0
Original line number Original line Diff line number Diff line
@@ -62,6 +62,7 @@ export default L.LayerCollection = L.Class.extend({
   * @param  {List} layers - List of overlay information.
   * @param  {List} layers - List of overlay information.
   */
   */
  createOverlays: function(layers) {
  createOverlays: function(layers) {
    
    for (let i = 0; i < layers.length; i++) {
    for (let i = 0; i < layers.length; i++) {
      let layer = layers[i];
      let layer = layers[i];
      let overlay = L.tileLayer.wms(
      let overlay = L.tileLayer.wms(
@@ -203,6 +204,7 @@ export default L.LayerCollection = L.Class.extend({
      map.target().toUpperCase() +
      map.target().toUpperCase() +
      "/WFS";
      "/WFS";



    let defaultParameters = {
    let defaultParameters = {
      service: "WFS",
      service: "WFS",
      version: "1.1.0",
      version: "1.1.0",