Unverified Commit aa7c2a4b authored by Jacob's avatar Jacob Committed by GitHub
Browse files

Merge branch 'master' into jrc632_GeoSTAC

parents e292d90a af293bbe
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@
    "react-dom": "^16.12.0",
    "requirejs": "^2.3.6",
    "typeface-roboto": "0.0.75",
    "wicket": "1.3.5"
    "wicket": "1.3.5",
    "leaflet-html-legend":"0.3.5"
  }
}
+40 −0
Original line number Diff line number Diff line

function callAPI() {
    return fetch("https://stac.astrogeology.usgs.gov/api/collections")
           .then(response => response.json());
}

function getItemCollection(name, page) {
  var urlArray = [];
  return callAPI().then(result => {
    for (let i = 0; i < result.collections.length; i++) {
      if (result.collections[i].summaries["ssys:targets"] == name.toLowerCase()) {
        let length = result.collections[i].links.length;
        for (let j = 0; j < length; j++) {
          let link = result.collections[i].links[j];
          if (link.rel == 'items') {
            var url = result.collections[i].links[j].href;
            // this is temporary until stac.astrogeology is working with pagination
            url = url.replace("https://stac.astrogeology.usgs.gov/api/collections", "https://jat52qc8c0.execute-api.us-west-2.amazonaws.com/dev/collections");
            url = url + "?page=" + page;
            urlArray.push(url);
          }
         }
       }
     }
     if (urlArray.length == 0) {
       return;
     }
     let promiseArray = [];
     for (let i = 0; i < urlArray.length; i++) {
       promiseArray.push(fetch(urlArray[i]));
     }
     return Promise.all(promiseArray).then(function (responses) {
        return Promise.all(responses.map(function (response) {
	           return response.json();
        }));
      });
   })
 }

export{ getItemCollection };
+76 −0
Original line number Diff line number Diff line
@@ -3,7 +3,9 @@ import "proj4leaflet";

import AstroProj from "./AstroProj";
import LayerCollection from "./LayerCollection";
import { getItemCollection, url } from "./ApiJsonCollection";
import { MY_JSON_MAPS } from "./layers";
import "leaflet-html-legend";

/**
 * @class AstroMap
@@ -43,6 +45,9 @@ export default L.Map.AstroMap = L.Map.extend({
      a: "",
      c: ""
    };
    this._footprintCollection = {};
    this._footprintControl = null;
    this._geoLayer = null;

    // Set by layer collection or baselayerchange event
    this._currentLayer = null;
@@ -90,6 +95,8 @@ export default L.Map.AstroMap = L.Map.extend({
    L.Map.prototype.initialize.call(this, this._mapDiv, this.options);
    this.loadLayerCollection("cylindrical");

    this.loadFootprintLayer(target, 1);

    // Listen to baselayerchange event so that we can set the current layer being
    // viewed by the map.
    this.on("baselayerchange", function(e) {
@@ -107,6 +114,75 @@ export default L.Map.AstroMap = L.Map.extend({
    this.layers[name].addTo(this);
  },

  /**
   * @function AstroMap.prototype.loadFootprintLayer
   * @description Adds the ApiJsonCollection with the requested name.
   *
   * @param {String} name - Name of the target
   *
   * @param {Int} page - current selected page number of the pagination
   */
  loadFootprintLayer: function(name, page) {
    getItemCollection(name, page).then(result => {
      if (result != undefined) {
        this._geoLayer = L.geoJSON().addTo(this);
        this._footprintCollection["Footprints"] = this._geoLayer;
        for (let i = 0; i < result.length; i++) {
          for (let j = 0; j < result[i].features.length; j++) {
            this._geoLayer.addData(result[i].features[j]);
          }
        }
        this._footprintControl = L.control.layers(null, this._footprintCollection).addTo(this);
        this.addFootprintLegend(name, page);
      }
    });
  },


  /**
   * @function AstroMap.prototype.addFootprintLegend
   * @description Adds legend for each footprint layer
   *
   * @param {String} name - Name of the projection
   *
   * @param {Int} page - current selected page number of the pagination
   */
  addFootprintLegend: function(name, page) {
    var self = this;

    var legend = L.control.htmllegend({
      legends: [{
          name: 'Footprints',
          layer: this._geoLayer,
          elements: [{
              html: `<div class="pagination">
                      <a id=footprint_left>&laquo;</a>
                      <a id=footprint_pageNumber>${page}</a>
                      <a id=footprint_right>&raquo;</a>
                    </div>`
          }]
        }]
     });
    this.addControl(legend);

    $('#footprint_right').click(function () {
      page = page + 1;
      self._footprintControl.remove();
      self._geoLayer.clearLayers();
      self.removeControl(legend);
      self.loadFootprintLayer(name, page);
    });
    $('#footprint_left').click(function () {
      page = page - 1;
      if (page > 0) {
        self._footprintControl.remove();
        self._geoLayer.clearLayers();
        self.removeControl(legend);
        self.loadFootprintLayer(name, page);
      }
    });
  },

  /**
   * @function AstroMap.prototype.parseJSON
   * @description Parses the USGS JSON, creates layer objects for a particular target and projection,
+14 −1
Original line number Diff line number Diff line
@import "../node_modules/leaflet/dist/leaflet.css";
@import "../node_modules/leaflet-fullscreen/dist/leaflet.fullscreen.css";
@import "https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css";
@import "../node_modules/leaflet-html-legend/dist/L.Control.HtmlLegend.css";


#map-container {
  width: 800px;
@@ -136,3 +138,14 @@ summary {
  padding: auto;
  vertical-align: center;
}

.pagination {
   display: inline-block;
}

.pagination a {
  color: black;
  float: left;
  padding: 8px 16px;
  text-decoration: none;
}