From 4b8bec46263562372f03c5b33b6a8ecd2d8d00e0 Mon Sep 17 00:00:00 2001 From: jbyrne Date: Tue, 3 Oct 2023 16:18:51 -0700 Subject: [PATCH] fix/hitide-ui-33: fix scaling of collections resolutions --- src/jpl/dijit/Search.js | 2 ++ src/jpl/dijit/ui/MetadataDialog.js | 29 ++++++++++++++++++++++----- src/jpl/utils/SearchDatasets.js | 32 +++++++++--------------------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/jpl/dijit/Search.js b/src/jpl/dijit/Search.js index 1321a743..363cbac8 100644 --- a/src/jpl/dijit/Search.js +++ b/src/jpl/dijit/Search.js @@ -521,6 +521,8 @@ define([ if (keys[i] === "DatasetCoverage-StartTimeLong" || keys[i] === "DatasetCoverage-StopTimeLong") { value = value ? moment.utc(parseInt(value)) : moment.utc(); + } else if (keys[i] === "Dataset-Resolution") { + value = valueArr } formattedObjs[keys[i]] = value; } diff --git a/src/jpl/dijit/ui/MetadataDialog.js b/src/jpl/dijit/ui/MetadataDialog.js index 91b2d39e..3e4d1839 100644 --- a/src/jpl/dijit/ui/MetadataDialog.js +++ b/src/jpl/dijit/ui/MetadataDialog.js @@ -78,12 +78,31 @@ define([ /* Set long name */ domAttr.set(this.metadataDatasetLongName, "innerHTML", metadata["Dataset-LongName"]); - /* Set along/across-track resolution */ - var alongTrackResolution = metadata["Dataset-AlongTrackResolution"]; - var acrossTrackResolution = metadata["Dataset-AcrossTrackResolution"]; - if(alongTrackResolution && acrossTrackResolution) - domAttr.set(this.metadataAlongAcrossRes, "innerHTML", parseInt(metadata["Dataset-AlongTrackResolution"]) / 1000 + "km x " + parseInt(metadata["Dataset-AcrossTrackResolution"]) / 1000 + "km"); + var datasetResolution = metadata["Dataset-Resolution"] + if(datasetResolution) { + // Set the resolution to display. Allow for multiple resolutions of one collection. + var unit = "km" + var multiplier = 0.001 + var resolutionString = "" + var datasetResolutionToUse = datasetResolution[0] + + // if Dataset-ShortName starts with SWOT_L2_NALT, then use the second value instead of the first + if (metadata["Dataset-ShortName"].includes("SWOT_L2_NALT")) { + datasetResolutionToUse = datasetResolution[1] + } + + // if meters, convert to km unless less than 1000 + // if kilometers, keep as km + if (datasetResolutionToUse["Unit"] === "Meters" && datasetResolutionToUse["Dataset-AlongTrackResolution"] < 1000) { + unit = "m" + multiplier = 1 + } else if (datasetResolutionToUse["Unit"] === "Kilometers") { + multiplier = 1 + } + resolutionString += parseInt(datasetResolutionToUse["Dataset-AlongTrackResolution"]) * multiplier + unit + " x " + parseInt(datasetResolutionToUse["Dataset-AcrossTrackResolution"]) * multiplier + unit + domAttr.set(this.metadataAlongAcrossRes, "innerHTML", resolutionString); + } else domAttr.set(this.metadataAlongAcrossRes, "innerHTML", "Not Available"); diff --git a/src/jpl/utils/SearchDatasets.js b/src/jpl/utils/SearchDatasets.js index 5a258cf9..8ea26f79 100644 --- a/src/jpl/utils/SearchDatasets.js +++ b/src/jpl/utils/SearchDatasets.js @@ -126,8 +126,6 @@ define([ function getCmrSpatialExtent(datasetObject){ var conceptId = datasetObject["Dataset-PersistentId"] - // var url = config.hitide.externalConfigurables.cmrVariableService; - // var customQuery = "{\n collection (conceptId: \"" + conceptId + "\") {\n spatialExtent \n} \n}" var secondURL = config.hitide.externalConfigurables.cmrCollectionSearchService + "/" + conceptId + ".umm_json" return request(secondURL, { handleAs: 'json', @@ -138,31 +136,19 @@ define([ }).then(function(response) { var resolutionAndCoordinateSystemObject = response.SpatialExtent.HorizontalSpatialDomain.ResolutionAndCoordinateSystem if (resolutionAndCoordinateSystemObject) { - var resolutionObject = resolutionAndCoordinateSystemObject.HorizontalDataResolution.GenericResolutions[0] - if (resolutionObject) { - datasetObject["Dataset-AcrossTrackResolution"] = resolutionObject.XDimension - datasetObject["Dataset-AlongTrackResolution"] = resolutionObject.YDimension + var resolutionObjects = resolutionAndCoordinateSystemObject.HorizontalDataResolution.GenericResolutions + if (resolutionObjects) { + 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}) + }); } } return datasetObject }) - // NOTE: Example of Graphql implementation of above query - // return request.post(url, { - // handleAs: 'json', - // withCredentials: config.hitide.externalConfigurables.crossOriginCmrCookies, - // headers: { "X-Requested-With": null, "Content-Type": "application/json" }, - // data: JSON.stringify({ query: customQuery }) - // }).then(function(response) { - // var resolutionAndCoordinateSystemObject = response.data.collection.spatialExtent.horizontalSpatialDomain.resolutionAndCoordinateSystem - // if (resolutionAndCoordinateSystemObject) { - // var resolutionObject = resolutionAndCoordinateSystemObject.horizontalDataResolution.genericResolutions[0] - // if (resolutionObject) { - // datasetObject["Dataset-AcrossTrackResolution"] = resolutionObject.xDimension - // datasetObject["Dataset-AlongTrackResolution"] = resolutionObject.yDimension - // } - // } - // return datasetObject - // }) } function getAdditionalCmrMetadata(collectionObjectArray) {