Unverified Commit d4ad0e9b authored by amystamile's avatar amystamile Committed by GitHub
Browse files

Merge pull request #10 from amystamile/toggleFootprints

Adds footprint layer for each mission.
parents 5546b37f a9ce0e4a
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@ function callAPI() {
function getStacTargetCatalog(name) {
  if (name == "Mars") {
    return callAPI().then(result => {
      console.log("STAC Catalog for USGS: ");
      console.log(result);
      for (let i = 0; i < result.links.length; i++) {
        if (result.links[i].title == 'Mars Analysis Ready Data') {
          return fetch(result.links[i].href)
@@ -20,8 +18,6 @@ function getStacTargetCatalog(name) {
  }
  if (name == "Europa") {
    return callAPI().then(result => {
      console.log("STAC Catalog for USGS: ");
      console.log(result);
      for (let i = 0; i < result.links.length; i++) {
        if (result.links[i].title == 'Jupiter Analysis Ready Data') {
          return fetch(result.links[i].href)
@@ -35,8 +31,6 @@ function getStacTargetCatalog(name) {

function getStacMissionCatalogs(name) {
  return getStacTargetCatalog(name).then(result => {
    console.log("STAC Catalog(s) for Specific Target: ");
    console.log(result);
    for (let i = 0; i < result.links.length; i++) {
      if(result.links[i].rel == 'child'){
        return fetch(result.links[i].href)
@@ -51,8 +45,6 @@ function getItemCollection(name) {
  // takes you straight to the collection from the target catalog
  if (name == "Mars"){
    return getStacTargetCatalog(name).then(result => {
      console.log("STAC Catalog(s) for Specific Target: ");
      console.log(result);
      for (let i = 0; i < result.links.length; i++) {
        if (result.links[i].rel == 'child') {
          return fetch(result.links[i].href)
@@ -63,10 +55,14 @@ function getItemCollection(name) {
  }
  if (name == "Europa") {
    return getStacMissionCatalogs(name).then(result => {
      console.log("STAC Collection for Specific Mission: ");
      console.log(result);
      return fetch(result.links[3].href)
        .then(response => response.json())
        return Promise.all([
          fetch(result.links[3].href),
          fetch(result.links[4].href)
        ]).then(function (responses) {
	         return Promise.all(responses.map(function (response) {
		           return response.json();
	         }));
      });
    })
  }
}
+17 −10
Original line number Diff line number Diff line
@@ -119,18 +119,25 @@ export default L.Map.AstroMap = L.Map.extend({
   * @param {String} name - Name of the STAC Catalog. example "ctx_dtms"
   */
  loadFootprintLayer: function(name) {
    var footprintLayer = L.geoJSON().addTo(this);
    var geoLayers = [];
    var footprintCollection = {};

    getItemCollection(name).then(result => {
        console.log("STAC Item Collection: ");
        console.log(result);
          for (let i = 0; i < result.links.length; i++) {
            if (result.links[i].rel == 'item') {
              fetch(result.links[i].href)
      let geoLayers = new Array(result.length);
      for (let i = 0; i < result.length; i++) {
        geoLayers[i] = L.geoJSON().addTo(this);
        footprintCollection[result[i].id] = geoLayers[i];
        for (let j = 0; j < result[i].links.length; j++) {
          if (result[i].links[j].rel == 'item') {
            fetch(result[i].links[j].href)
              .then(response => response.json())
                .then(data => footprintLayer.addData(data))
              .then(function(data) {
                geoLayers[i].addData(data);
              })
          }
        }
      }
      L.control.layers(null, footprintCollection).addTo(this);
    });
  },