Skip to content

Commit

Permalink
#462 IdentifierTool - Query Datasets with Time (#463)
Browse files Browse the repository at this point in the history
* #462 IdentifierTool - Query Datasets with Time

* #462 IdentifierTool timeFormat docs
  • Loading branch information
tariqksoliman committed Dec 6, 2023
1 parent c0f7a35 commit 692d025
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/pages/Tools/Identifier/Identifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ The following is an example of the Sites Tool's Tool Tab configuration:
"url": "(str) path_to_data/data.tif",
"bands": "(int) how many bands to query from",
"sigfigs": "(int) how many digits after the decimal",
"unit": "(str) whatever string unit"
"unit": "(str) whatever string unit",
"timeFormat": "(str) for formatting injected '{starttime}' and '{endtime}' in url."
},
"...": {}
}
```

- `Layer_Name`: This is the layer name exactly as it appears in the Layers section in the configuration.
- `url`: This can be a relative path to a file under the Mission name or a full url path. The former is preferred is the file is large.
- `url`: This can be a relative path to a file under the Mission name or a full url path. The former is preferred is the file is large. Can use '{starttime}' and '{endtime}' if the layer is time enabled.
- `bands`: Allows you to specify how many bands to return data from. Default is 1.
- `sigfigs`: Sets the decimal precision.
- `unit`: A string that is appended to your returned value. e.g. " m" would be appended on a raw value ("41") and show "41 m". If it was "m", it would return "41m", without a space.
- `timeFormat`: A string for formatting the injected '{starttime}' and '{endtime}' in the url. See syntax in https://d3js.org/d3-time-format#locale_format
30 changes: 29 additions & 1 deletion src/essence/Tools/Identifier/IdentifierTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ var IdentifierTool = {
destroy: function () {
this.MMWebGISInterface.separateFromMMWebGIS()
},
fillURLParameters: function (url, layerUUID) {
if (IdentifierTool.vars[layerUUID]) {
const layerTimeFormat = d3.utcFormat(
IdentifierTool.vars[layerUUID].timeFormat
)

let filledURL = url
filledURL = filledURL
.replace(
/{starttime}/g,
layerTimeFormat(
Date.parse(L_.layers.data[layerUUID].time.start)
)
)
.replace(
/{endtime}/g,
layerTimeFormat(
Date.parse(L_.layers.data[layerUUID].time.end)
)
)

return filledURL
} else return url
},
//From: https://github.com/mrdoob/three.js/issues/758 mrdoob
getImageData: function (image) {
if (image.width == 0) return
Expand Down Expand Up @@ -240,6 +264,7 @@ var IdentifierTool = {
lnglatzoom[1],
IdentifierTool.vars[IdentifierTool.activeLayerNames[i]]
.bands,
IdentifierTool.activeLayerNames[i],
(function (pxRGBA, i) {
return function (value) {
var htmlValues = ''
Expand Down Expand Up @@ -442,14 +467,17 @@ function bestMatchInLegend(rgba, legendData) {
return bestMatch
}

function queryDataValue(url, lng, lat, numBands, callback) {
function queryDataValue(url, lng, lat, numBands, layerUUID, callback) {
numBands = numBands || 1
var dataPath
if (url.startsWith('/vsicurl/')) {
dataPath = url
} else {
dataPath = 'Missions/' + L_.mission + '/' + url
}

dataPath = IdentifierTool.fillURLParameters(dataPath, layerUUID)

calls.api(
'getbands',
{
Expand Down
3 changes: 2 additions & 1 deletion src/essence/Tools/Identifier/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"url": "(str) path_to_data/data.tif",
"bands": "(int) how many bands to query from",
"sigfigs": "(int) how many digits after the decimal",
"unit": "(str) whatever string unit"
"unit": "(str) whatever string unit",
"timeFormat": "(str) for injecting '{starttime}' and '{endtime}' in url. See syntax in https://d3js.org/d3-time-format#locale_format"
},
"...": {}
}
Expand Down

0 comments on commit 692d025

Please sign in to comment.