Skip to content

Commit

Permalink
issue/hitide-ui-48: help catch collection resolution errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jbyrne committed Feb 13, 2024
1 parent 4bc66eb commit 29a557f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
59 changes: 32 additions & 27 deletions src/jpl/dijit/ui/MetadataDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ define([
/* Set along/across-track resolution */
var datasetResolution = metadata["Dataset-Resolution"]

if(datasetResolution) {
if (datasetResolution) {
// Set the resolution to display. Allow for multiple resolutions of one collection.
var unit = "km"
var multiplier = 0.001
Expand All @@ -91,37 +91,42 @@ define([
// if meters, convert to km unless less than 1000
// if kilometers, keep as km
for(var i=0; i<datasetResolution.length; i++) {
if (datasetResolution[i]["Unit"] === "Meters" && datasetResolution[i]["Dataset-AlongTrackResolution"] < 1000) {
unit = "m"
multiplier = 1
} else if (datasetResolution[i]["Unit"] === "Kilometers") {
multiplier = 1
var datasetResolutionError = datasetResolution[i]["error"]
if (datasetResolutionError === "No Error") {
if (datasetResolution[i]["Unit"] === "Meters" && datasetResolution[i]["Dataset-AlongTrackResolution"] < 1000) {
unit = "m"
multiplier = 1
} else if (datasetResolution[i]["Unit"] === "Kilometers") {
multiplier = 1
}

// if on the last dataset resolution object
if (i === datasetResolution.length - 1) {
connectingSting = ""
}

var alongTrackString = (parseFloat(datasetResolution[i]["Dataset-AlongTrackResolution"]) * multiplier).toString()
var acrossTrackString = (parseFloat(datasetResolution[i]["Dataset-AcrossTrackResolution"]) * multiplier).toString()
// round resolution strings to precision of 2 without trailing zeros if too long
if (alongTrackString.split(".")[1] && alongTrackString.split(".")[1].length > 2) {
alongTrackString = parseFloat(parseFloat(alongTrackString).toFixed(2)).toString()
}
if (acrossTrackString.split(".")[1] && acrossTrackString.split("."[1]).length > 2) {
acrossTrackString = parseFloat(parseFloat(acrossTrackString).toFixed(2)).toString()
}

resolutionString += alongTrackString + unit + " x " + acrossTrackString + unit + connectingSting
// domAttr.set(this.metadataAlongAcrossRes, "innerHTML", resolutionString);
} else {
resolutionString = datasetResolutionError
}

// if on the last dataset resolution object
if (i === datasetResolution.length - 1) {
connectingSting = ""
}

var alongTrackString = (parseFloat(datasetResolution[i]["Dataset-AlongTrackResolution"]) * multiplier).toString()
var acrossTrackString = (parseFloat(datasetResolution[i]["Dataset-AcrossTrackResolution"]) * multiplier).toString()
// round resolution strings to precision of 2 without trailing zeros if too long
if (alongTrackString.split(".")[1] && alongTrackString.split(".")[1].length > 2) {
alongTrackString = parseFloat(parseFloat(alongTrackString).toFixed(2)).toString()
}
if (acrossTrackString.split(".")[1] && acrossTrackString.split("."[1]).length > 2) {
acrossTrackString = parseFloat(parseFloat(acrossTrackString).toFixed(2)).toString()
}

resolutionString += alongTrackString + unit + " x " + acrossTrackString + unit + connectingSting
}

domAttr.set(this.metadataAlongAcrossRes, "innerHTML", resolutionString);
} else {
domAttr.set(this.metadataAlongAcrossRes, "innerHTML", "Issue Loading Resolution");
}
else
// domAttr.set(this.metadataAlongAcrossRes, "innerHTML", "Not Available");
domAttr.set(this.metadataAlongAcrossRes, "innerHTML", "Not Applicable");


/* Set date range */
var startDate = metadata["DatasetCoverage-StartTimeLong"];
var formattedStart = "Unknown";
Expand Down
12 changes: 10 additions & 2 deletions src/jpl/utils/SearchDatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ define([
var promises = [];
if(typeof cmrSearchUrl === 'string') promises.push(searchCmr(options));
if(promises.length === 0) {
// eslint-disable-next-line no-console
console.log('Did not enable cmr datasets');
}

Expand Down Expand Up @@ -133,19 +134,26 @@ define([
},
withCredentials: config.hitide.externalConfigurables.crossOriginCmrCookies
}).then(function(response) {
datasetObject["Dataset-Resolution"] = []
var resolutionAndCoordinateSystemObject = response.SpatialExtent.HorizontalSpatialDomain.ResolutionAndCoordinateSystem
var relatedUrlsArray = response.RelatedUrls
if (resolutionAndCoordinateSystemObject) {
var resolutionObjects = resolutionAndCoordinateSystemObject.HorizontalDataResolution.GenericResolutions
if (resolutionObjects) {
datasetObject["Dataset-Resolution"] = []
// datasetObject["Dataset-Resolution"] = []
resolutionObjects.forEach(function(resolutionObject) {
var acrossTrack = resolutionObject.XDimension
var alongTrack = resolutionObject.YDimension
var unit = resolutionObject.Unit
datasetObject["Dataset-Resolution"].push({"Dataset-AcrossTrackResolution": acrossTrack, "Dataset-AlongTrackResolution": alongTrack, "Unit": unit})
datasetObject["Dataset-Resolution"].push({"Dataset-AcrossTrackResolution": acrossTrack, "Dataset-AlongTrackResolution": alongTrack, "Unit": unit, "error": "No Error"})
});
} else {
// resolution not applicable
datasetObject["Dataset-Resolution"].push({"error": "Issue Loading Resolution"})
}
} else {
// probably an error and not (not applicable)
datasetObject["Dataset-Resolution"].push({"error": "Not Applicable"})
}
if (relatedUrlsArray) {
for(var i=0; i < relatedUrlsArray.length; i++) {
Expand Down

0 comments on commit 29a557f

Please sign in to comment.