78 lines
3.2 KiB
JavaScript
Executable file
78 lines
3.2 KiB
JavaScript
Executable file
$.ajax({
|
|
url: "https://data.nasa.gov/resource/gh4g-9sfh.json",
|
|
type: "GET",
|
|
data: {
|
|
"$limit" : 500,
|
|
"$$app_token" : "VLkZXiizqqIPBNNauahdq1mdq"
|
|
}
|
|
}).done(function(data) {
|
|
|
|
document.getElementById("infoBar").innerHTML += "<h5>Mostrant " + data.length + " resultats</h5>";
|
|
// document.getElementById("infoBar").innerHTML += "<h5>Massa total " + massAdd()[1] + "(kg) / Massa mitjana " + massAdd()[0] + "(g)</h5>";
|
|
console.log(data);
|
|
|
|
var map = L.map('map').setView([35, 0], 2.35);
|
|
|
|
// L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
|
|
// attribution: 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
|
|
// maxZoom: 18,
|
|
// id: 'mapbox/streets-v11',
|
|
// tileSize: 512,
|
|
// zoomOffset: -1,
|
|
// accessToken: 'pk.eyJ1Ijoicm9nZXJwYjk4IiwiYSI6ImNreTh6Y3VqODAxZGwydXA0dDA5emM1MngifQ.mzj9oEzGlCAcKTS5vKJi0w'
|
|
// }).addTo(map);
|
|
L.esri.basemapLayer('Topographic').addTo(map);
|
|
|
|
|
|
// showMarkers(data);
|
|
|
|
showTable(data);
|
|
|
|
|
|
|
|
// showMap();
|
|
});
|
|
function showMarkers(data) {
|
|
for (let i=0; i<data.length; i++) {
|
|
let lon =(typeof data[i]["geolocation"]["longitude"] !== "undefined" ? data[i]["geolocation"]["longitude"].substring(0, 5) : "N/A");
|
|
let lat =(typeof data[i]["geolocation"]["latitude"] !== "undefined" ? data[i]["geolocation"]["latitude"].substring(0, 5) : "N/A");
|
|
let markerColor = (typeof data[i]["mass"] == "undefined)" ? 'blue' : (data[i]["mass"] <=1000 ? 'green' : (data[i]["mass"] > 1000 && data[i]["mass"] <= 100000 ? 'yellow' : 'red')));
|
|
|
|
var circle = L.circle([lon, lat], {
|
|
color: markerColor,
|
|
radius: 50000
|
|
}).addTo(map);
|
|
circle.bindPopup(
|
|
"Name: " + data[i]["name"] + "<br>" +
|
|
"Class: " + (typeof data[i]["recclass"] !== "undefined" ? data[i]["recclass"] : "N/A") + "<br>" +
|
|
"Mass: " + (typeof data[i]["mass"] !== "undefined" ? data[i]["mass"] : "N/A") + "<br>" +
|
|
"Year: " + (typeof data[i]["year"] !== "undefined" ? data[i]["year"].substring(0, 4) : "N/A") + "<br>" +
|
|
"Georication: " + lon + " / " + lat
|
|
);
|
|
|
|
}
|
|
}
|
|
|
|
function showTable(data) {
|
|
for (let i=0; i<data.length; i++) {
|
|
document.getElementById("contentTable").innerHTML +=
|
|
`<tr>
|
|
<td>` + data[i]["id"] + `</td>
|
|
<td>` + data[i]["name"] + `</td>
|
|
<td>` + (typeof data[i]["recclass"] !== "undefined" ? data[i]["recclass"] : "N/A") + `</td>
|
|
<td>` + (typeof data[i]["mass"] !== "undefined" ? data[i]["mass"] : "N/A") + `</td>
|
|
<td>` + (typeof data[i]["year"] !== "undefined" ? data[i]["year"].substring(0, 4): "N/A") + `</td>
|
|
<td>` + (typeof data[i]["geolocation"]["latitude"] !== "undefined" || data[i]["geolocation"]["longitude"] !== "undefined" ? data[i]["geolocation"]["latitude"] + " / " + data[i]["geolocation"]["longitude"] : "N/A") + `</td>
|
|
</tr>`
|
|
}
|
|
}
|
|
function massAdd() {
|
|
var rs = new Array(2);
|
|
for (let i=0; i<data.length; i++) {
|
|
rs[0] += (!isNaN(parseInt(data[i]["mass"]))) ? parseInt(data[i]["mass"]) : 0;
|
|
}
|
|
rs[1] = rs[0]/1000;
|
|
return rs;
|
|
|
|
}
|