Skip to content

Commit a89f6e4

Browse files
authored
Update MONet parsing to be consistent with updated source data format (#112)
1 parent 56771de commit a89f6e4

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

docs/map/index.html

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,30 @@
327327
});
328328
console.debug(`Created ${jgiGoldOrgObjs.length} markers.`);
329329

330-
// Fetch the EMSL MONet JSON (not CSV) file and create a marker for each element of its top-level array.
330+
// Fetch the EMSL MONet JSON (not CSV) file and create a marker for each BERtron entity represented within it.
331331
const monetResponse = await fetch(
332332
`${baseUrlForData}/emsl/map/monet_samples_schema-9-16-2025.json`,
333333
);
334334
const monetObjs = await monetResponse.json();
335335
const monetMarkers = [];
336336
console.debug("Fetching and parsing finished.", { data: monetObjs });
337337
monetObjs.forEach((obj) => {
338-
const latLon = getLatLon(obj);
339-
const identifier = `Project: ${obj["proposal_id"]}, Sampling set: ${obj["sampling_set"]}`;
340-
const url = `https://sc-data.emsl.pnnl.gov/?projectId=${obj["proposal_id"]}`;
338+
// If the object lacks a `coordinates` field (which the BERtron schema says is possible),
339+
// omit the object from the map and display a warning on the JavaScript console.
340+
if (!obj.hasOwnProperty("coordinates")) {
341+
console.warn("Omitting object lacking coordinates:", obj);
342+
return; // skips to the next iteration
343+
}
344+
345+
// If the object lacks an `id` field (which the BERtron schema says is possible),
346+
// use a generic value.
347+
const identifier = obj.hasOwnProperty("id") ? obj["id"] : "Sample";
348+
349+
// At this point, we know the object has a `coordinates` field, so we access it.
350+
const coordinates = obj["coordinates"];
351+
const latLon = getLatLon(coordinates);
352+
353+
const url = obj["uri"];
341354
const popupHtml = `<div class="vstack gap-3 marker-popup"><img src="./img/emsl-100x100.png" alt="Logo"/><div>EMSL MONet Sample<br/><a href="${url}" target="_blank" title="View project" class="identifier">${identifier}</a></div></div>`;
342355
const icon = L.icon({
343356
iconUrl: "./img/emsl-marker.png",

0 commit comments

Comments
 (0)