Loading app/src/js/ApiJsonCollection.js +33 −26 Original line number Diff line number Diff line function callAPI() { return fetch("https://stac.astrogeology.usgs.gov/api/collections") .then(response => response.json()); return fetch( "https://stac.astrogeology.usgs.gov/api/collections" ).then(response => response.json()); } function getItemCollection(name, page) { function getItemCollection(name, queryString) { var urlArray = []; return callAPI().then(result => { for (let i = 0; i < result.collections.length; i++) { if (result.collections[i].summaries["ssys:targets"] == name.toLowerCase()) { 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') { 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; url = url.replace( "https://stac.astrogeology.usgs.gov/api/collections", "https://jat52qc8c0.execute-api.us-west-2.amazonaws.com/dev/collections" ); url = url + queryString; urlArray.push(url); } } Loading @@ -30,11 +35,13 @@ function getItemCollection(name, page) { promiseArray.push(fetch(urlArray[i])); } return Promise.all(promiseArray).then(function(responses) { return Promise.all(responses.map(function (response) { return Promise.all( responses.map(function(response) { return response.json(); })); }); }) ); }); }); } export { getItemCollection }; No newline at end of file app/src/js/AstroDrawControl.js +39 −8 Original line number Diff line number Diff line Loading @@ -91,6 +91,41 @@ export default L.Control.AstroDrawControl = L.Control.Draw.extend({ this.wkt.read(JSON.stringify(geoJson)); this.wktTextBox.value = this.wkt.write(); this.shapesToFootprint(this.wktTextBox.value); }, /** * @function shapesToFootprint * @description Is called when a user draws a shape using the on map drawing features. * Renders all footprints that intersect the drawn area. * * @param {String} coords - The drawn shape’s coordinates. */ shapesToFootprint: function(coords) { let strArr = coords .slice(coords.indexOf("((") + 2, coords.indexOf("))")) .split(","); let bboxCoordArr = []; for (let i = 0; i < 3; i++) { if (i != 1) { let temp = strArr[i].split(" "); bboxCoordArr.push([parseFloat(temp[0]), parseFloat(temp[1])]); } } // will proballby end up refactoring this a little bit when the front end of // this is up let bboxArr = [ bboxCoordArr[0][0], bboxCoordArr[0][1], bboxCoordArr[1][0], bboxCoordArr[1][1] ]; this._map._footprintControl.remove(); this._map._geoLayer.clearLayers(); this._map.removeControl(this._map._htmllegend); let queryString = "?bbox=" + "[" + bboxArr + "]"; this._map.loadFootprintLayer(this._map._name, queryString); }, /** Loading Loading @@ -122,8 +157,4 @@ export default L.Control.AstroDrawControl = L.Control.Draw.extend({ this.myLayer.addData(geojsonFeature); } // reprojectFeature: function(e) { // } }); No newline at end of file app/src/js/AstroMap.js +45 −23 Original line number Diff line number Diff line Loading @@ -48,6 +48,9 @@ export default L.Map.AstroMap = L.Map.extend({ this._footprintCollection = {}; this._footprintControl = null; this._geoLayer = null; this._name = null; this._htmllegend = null; this._currentPage = 1; // Set by layer collection or baselayerchange event this._currentLayer = null; Loading Loading @@ -95,7 +98,7 @@ 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); this.loadFootprintLayer(target, "?page=" + this._currentPage); // Listen to baselayerchange event so that we can set the current layer being // viewed by the map. Loading @@ -120,11 +123,16 @@ export default L.Map.AstroMap = L.Map.extend({ * * @param {String} name - Name of the target * * @param {Int} page - current selected page number of the pagination * @param {String} queryString - Filter for deisered footprints ie: ?page=1 * * @param {Boolean} loadFootprintLegend - Boolean value used to bypass adding * the FootprintLegend */ loadFootprintLayer: function(name, page) { getItemCollection(name, page).then(result => { loadFootprintLayer: function(name, queryString, loadFootprintLegend = true) { console.log("in loadFootprint\n", queryString); getItemCollection(name, queryString).then(result => { if (result != undefined) { this._name = name; this._geoLayer = L.geoJSON().addTo(this); this._footprintCollection["Footprints"] = this._geoLayer; for (let i = 0; i < result.length; i++) { Loading @@ -132,8 +140,14 @@ export default L.Map.AstroMap = L.Map.extend({ this._geoLayer.addData(result[i].features[j]); } } this._footprintControl = L.control.layers(null, this._footprintCollection).addTo(this); this.addFootprintLegend(name, page); this._footprintControl = L.control .layers(null, this._footprintCollection) .addTo(this); if (loadFootprintLegend) { this.addFootprintLegend(name); } } }); }, Loading @@ -145,41 +159,49 @@ export default L.Map.AstroMap = L.Map.extend({ * * @param {String} name - Name of the projection * * @param {Int} page - current selected page number of the pagination */ addFootprintLegend: function(name, page) { addFootprintLegend: function(name) { var self = this; var legend = L.control.htmllegend({ legends: [{ name: 'Footprints', legends: [ { name: "Footprints", layer: this._geoLayer, elements: [{ elements: [ { html: `<div class="pagination"> <a id=footprint_left>«</a> <a id=footprint_pageNumber>${page}</a> <a id=footprint_pageNumber>${self._currentPage}</a> <a id=footprint_right>»</a> </div>` }] }] } ] } ] }); this._htmllegend = legend; this.addControl(legend); $('#footprint_right').click(function () { page = page + 1; $("#footprint_right").click(function() { self._currentPage += 1; self._footprintControl.remove(); self._geoLayer.clearLayers(); self.removeControl(legend); self.loadFootprintLayer(name, page); let queryString = "?page=" + self._currentPage; self.loadFootprintLayer(name, queryString); }); $('#footprint_left').click(function () { page = page - 1; if (page > 0) { $("#footprint_left").click(function() { self._currentPage -= 1; if (this._currentPage > 0) { self._footprintControl.remove(); self._geoLayer.clearLayers(); self.removeControl(legend); self.loadFootprintLayer(name, page); let queryString = "?page=" + self._currentPage; self.loadFootprintLayer(name, queryString); } // should add some error message here eventually }); }, Loading Loading
app/src/js/ApiJsonCollection.js +33 −26 Original line number Diff line number Diff line function callAPI() { return fetch("https://stac.astrogeology.usgs.gov/api/collections") .then(response => response.json()); return fetch( "https://stac.astrogeology.usgs.gov/api/collections" ).then(response => response.json()); } function getItemCollection(name, page) { function getItemCollection(name, queryString) { var urlArray = []; return callAPI().then(result => { for (let i = 0; i < result.collections.length; i++) { if (result.collections[i].summaries["ssys:targets"] == name.toLowerCase()) { 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') { 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; url = url.replace( "https://stac.astrogeology.usgs.gov/api/collections", "https://jat52qc8c0.execute-api.us-west-2.amazonaws.com/dev/collections" ); url = url + queryString; urlArray.push(url); } } Loading @@ -30,11 +35,13 @@ function getItemCollection(name, page) { promiseArray.push(fetch(urlArray[i])); } return Promise.all(promiseArray).then(function(responses) { return Promise.all(responses.map(function (response) { return Promise.all( responses.map(function(response) { return response.json(); })); }); }) ); }); }); } export { getItemCollection }; No newline at end of file
app/src/js/AstroDrawControl.js +39 −8 Original line number Diff line number Diff line Loading @@ -91,6 +91,41 @@ export default L.Control.AstroDrawControl = L.Control.Draw.extend({ this.wkt.read(JSON.stringify(geoJson)); this.wktTextBox.value = this.wkt.write(); this.shapesToFootprint(this.wktTextBox.value); }, /** * @function shapesToFootprint * @description Is called when a user draws a shape using the on map drawing features. * Renders all footprints that intersect the drawn area. * * @param {String} coords - The drawn shape’s coordinates. */ shapesToFootprint: function(coords) { let strArr = coords .slice(coords.indexOf("((") + 2, coords.indexOf("))")) .split(","); let bboxCoordArr = []; for (let i = 0; i < 3; i++) { if (i != 1) { let temp = strArr[i].split(" "); bboxCoordArr.push([parseFloat(temp[0]), parseFloat(temp[1])]); } } // will proballby end up refactoring this a little bit when the front end of // this is up let bboxArr = [ bboxCoordArr[0][0], bboxCoordArr[0][1], bboxCoordArr[1][0], bboxCoordArr[1][1] ]; this._map._footprintControl.remove(); this._map._geoLayer.clearLayers(); this._map.removeControl(this._map._htmllegend); let queryString = "?bbox=" + "[" + bboxArr + "]"; this._map.loadFootprintLayer(this._map._name, queryString); }, /** Loading Loading @@ -122,8 +157,4 @@ export default L.Control.AstroDrawControl = L.Control.Draw.extend({ this.myLayer.addData(geojsonFeature); } // reprojectFeature: function(e) { // } }); No newline at end of file
app/src/js/AstroMap.js +45 −23 Original line number Diff line number Diff line Loading @@ -48,6 +48,9 @@ export default L.Map.AstroMap = L.Map.extend({ this._footprintCollection = {}; this._footprintControl = null; this._geoLayer = null; this._name = null; this._htmllegend = null; this._currentPage = 1; // Set by layer collection or baselayerchange event this._currentLayer = null; Loading Loading @@ -95,7 +98,7 @@ 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); this.loadFootprintLayer(target, "?page=" + this._currentPage); // Listen to baselayerchange event so that we can set the current layer being // viewed by the map. Loading @@ -120,11 +123,16 @@ export default L.Map.AstroMap = L.Map.extend({ * * @param {String} name - Name of the target * * @param {Int} page - current selected page number of the pagination * @param {String} queryString - Filter for deisered footprints ie: ?page=1 * * @param {Boolean} loadFootprintLegend - Boolean value used to bypass adding * the FootprintLegend */ loadFootprintLayer: function(name, page) { getItemCollection(name, page).then(result => { loadFootprintLayer: function(name, queryString, loadFootprintLegend = true) { console.log("in loadFootprint\n", queryString); getItemCollection(name, queryString).then(result => { if (result != undefined) { this._name = name; this._geoLayer = L.geoJSON().addTo(this); this._footprintCollection["Footprints"] = this._geoLayer; for (let i = 0; i < result.length; i++) { Loading @@ -132,8 +140,14 @@ export default L.Map.AstroMap = L.Map.extend({ this._geoLayer.addData(result[i].features[j]); } } this._footprintControl = L.control.layers(null, this._footprintCollection).addTo(this); this.addFootprintLegend(name, page); this._footprintControl = L.control .layers(null, this._footprintCollection) .addTo(this); if (loadFootprintLegend) { this.addFootprintLegend(name); } } }); }, Loading @@ -145,41 +159,49 @@ export default L.Map.AstroMap = L.Map.extend({ * * @param {String} name - Name of the projection * * @param {Int} page - current selected page number of the pagination */ addFootprintLegend: function(name, page) { addFootprintLegend: function(name) { var self = this; var legend = L.control.htmllegend({ legends: [{ name: 'Footprints', legends: [ { name: "Footprints", layer: this._geoLayer, elements: [{ elements: [ { html: `<div class="pagination"> <a id=footprint_left>«</a> <a id=footprint_pageNumber>${page}</a> <a id=footprint_pageNumber>${self._currentPage}</a> <a id=footprint_right>»</a> </div>` }] }] } ] } ] }); this._htmllegend = legend; this.addControl(legend); $('#footprint_right').click(function () { page = page + 1; $("#footprint_right").click(function() { self._currentPage += 1; self._footprintControl.remove(); self._geoLayer.clearLayers(); self.removeControl(legend); self.loadFootprintLayer(name, page); let queryString = "?page=" + self._currentPage; self.loadFootprintLayer(name, queryString); }); $('#footprint_left').click(function () { page = page - 1; if (page > 0) { $("#footprint_left").click(function() { self._currentPage -= 1; if (this._currentPage > 0) { self._footprintControl.remove(); self._geoLayer.clearLayers(); self.removeControl(legend); self.loadFootprintLayer(name, page); let queryString = "?page=" + self._currentPage; self.loadFootprintLayer(name, queryString); } // should add some error message here eventually }); }, Loading