Skip to content

Commit

Permalink
#473 Layer Specific IdentifierTool vars 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Dec 15, 2023
1 parent b864a03 commit 15e966c
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 119 deletions.
14 changes: 12 additions & 2 deletions src/essence/Basics/Layers_/Layers_.js
Original file line number Diff line number Diff line change
Expand Up @@ -1782,16 +1782,26 @@ const L_ = {
}
return false
},
getToolVars: function (toolName, showWarnings) {
getToolVars: function (toolName, withVarsFromLayers, showWarnings) {
let vars = {}
for (var i = 0; i < L_.tools.length; i++) {
if (
L_.tools[i].hasOwnProperty('name') &&
L_.tools[i].name.toLowerCase() == toolName &&
L_.tools[i].hasOwnProperty('variables')
) {
return L_.tools[i].variables
vars = L_.tools[i].variables
}
}
if (withVarsFromLayers) {
vars.__layers = {}
L_.layers.dataFlat.forEach((d) => {
if (d.name != null && d?.variables?.tools?.[toolName] != null) {
vars.__layers[d.name] = d.variables.tools[toolName]
}
})
}
if (Object.keys(vars).length > 0) return vars
if (showWarnings)
console.warn(
`WARNING: Tried to get ${toolName} Tool's config variables and failed.`
Expand Down
254 changes: 137 additions & 117 deletions src/essence/Tools/Identifier/IdentifierTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,28 @@ var IdentifierTool = {
this.MMWebGISInterface = new interfaceWithMMWebGIS()

//Get tool variables
this.varsRaw = L_.getToolVars('identifier')
this.vars = {}
this.varsRaw = L_.getToolVars('identifier', true)
this.vars = {
data: {},
}
Object.keys(this.varsRaw).forEach((layerName) => {
this.vars[L_.asLayerUUID(layerName)] = this.varsRaw[layerName]
if (layerName != '__layers')
this.vars.data[L_.asLayerUUID(layerName)] = {
data: [this.varsRaw[layerName]],
}
})

if (this.varsRaw.__layers) {
Object.keys(this.varsRaw.__layers).forEach((layerName) => {
const layer = this.varsRaw.__layers[layerName]
if (layer.data) {
this.vars.data[layerName] = layer
}
})
}

console.log(this.vars)

//Probably always 256
this.tileImageWidth = 256
//x y and zoom of mousedover tile
Expand All @@ -57,9 +73,9 @@ var IdentifierTool = {
this.MMWebGISInterface.separateFromMMWebGIS()
},
fillURLParameters: function (url, layerUUID) {
if (IdentifierTool.vars[layerUUID]) {
if (IdentifierTool.vars.data[layerUUID]) {
const layerTimeFormat = d3.utcFormat(
IdentifierTool.vars[layerUUID].timeFormat
IdentifierTool.vars.data[layerUUID].timeFormat
)

let filledURL = url
Expand Down Expand Up @@ -120,28 +136,9 @@ var IdentifierTool = {
Globe_.litho.zoom,
])
},
idValueMap: function (e) {
IdentifierTool.idPixel(
e,
[e.latlng.lng, e.latlng.lat, Map_.map.getZoom()],
true
)
},
idValueGlobe: function (e) {
if (Globe_.litho.mouse)
IdentifierTool.idPixel(
e,
[
Globe_.litho.mouse.lng,
Globe_.litho.mouse.lat,
Globe_.litho.zoom,
],
true
)
},
//lnglatzoom is [lng,lat,zoom]
//if trueValue is true, query the data layer for the value, else us the legend if possible
idPixel: function (e, lnglatzoom, trueValue) {
idPixel: function (e, lnglatzoom, trueValue, selfish) {
trueValue = trueValue || false
clearTimeout(IdentifierTool.mousemoveTimeout)

Expand Down Expand Up @@ -258,106 +255,129 @@ var IdentifierTool = {
)
}
//Oh IdentifierTool is the same as X != undefined
if (pxRGBA) {
if (
trueValue &&
IdentifierTool.vars[IdentifierTool.activeLayerNames[i]]
) {
queryDataValue(
IdentifierTool.vars[IdentifierTool.activeLayerNames[i]]
.url,
lnglatzoom[0],
lnglatzoom[1],
IdentifierTool.vars[IdentifierTool.activeLayerNames[i]]
.bands,
IdentifierTool.activeLayerNames[i],
(function (pxRGBA, i) {
return function (value) {
var htmlValues = ''
var cnt = 0
for (var v in value) {
var unit =
IdentifierTool.vars[
IdentifierTool.activeLayerNames[i]
].unit || ''
if (
IdentifierTool.vars[
IdentifierTool.activeLayerNames[i]
].units &&
IdentifierTool.vars[
IdentifierTool.activeLayerNames[i]
].units.constructor === Array &&
IdentifierTool.vars[
IdentifierTool.activeLayerNames[i]
].units[cnt]
) {
unit =
IdentifierTool.vars[
if (
IdentifierTool.vars.data[IdentifierTool.activeLayerNames[i]]
?.data
) {
const data =
IdentifierTool.vars.data[IdentifierTool.activeLayerNames[i]]
for (let j = 0; j < data.data.length; j++) {
const d = data.data[j]

if (pxRGBA) {
if (trueValue) {
queryDataValue(
d.url,
lnglatzoom[0],
lnglatzoom[1],
d.bands,
IdentifierTool.activeLayerNames[i],
(function (pxRGBA, i, j) {
return function (value) {
const d2 =
IdentifierTool.vars.data[
IdentifierTool.activeLayerNames[
i
]
].units[cnt]
].data[j]
var htmlValues = ''
// first empty it
$(
`#identifierToolIdPixelCursorInfo_${i}_${j}`
).html(
[
'<div style="width: 100%; height: 22px; display: flex; justify-content: space-between;">',
'<div></div>',
'<div style="width: calc(100% - 4px); margin: 4px 4px 4px 0px; background: var(--color-a1);">&nbsp;</div>',
'</div>',
].join('')
)
var cnt = 0
for (var v in value) {
var unit = d2.unit || ''
if (
d2.units &&
d2.units.constructor ===
Array &&
d2.units[cnt]
) {
unit = d2.units[cnt]
}
var valueParsed =
parseValue(
value[v][1],
d2.sigfigs
) +
'' +
unit
htmlValues +=
'<div style="display: flex; justify-content: space-between;"><div style="margin-right: 15px; color: var(--color-a5); font-size: 12px;">' +
value[v][0] +
'</div><div style="color: var(--color-a6); font-size: 14px;">' +
valueParsed +
'</div></div>'
cnt++
}
$(
`#identifierToolIdPixelCursorInfo_${i}_${j}`
).html(htmlValues)
}
var valueParsed =
parseValue(
value[v][1],
IdentifierTool.vars[
IdentifierTool.activeLayerNames[
i
]
].sigfigs
) +
'' +
unit
htmlValues +=
'<div style="display: flex; justify-content: space-between;"><div style="margin-right: 15px;">' +
value[v][0] +
'</div><div>' +
valueParsed +
'</div></div>'
cnt++
}
$('#identifierToolIdPixelCursorInfo_' + i).html(
htmlValues
})(pxRGBA, i, j)
)
} else {
if (
L_.layers.data[
IdentifierTool.activeLayerNames[i]
]?._legend
) {
value = bestMatchInLegend(
pxRGBA,
L_.layers.data[
IdentifierTool.activeLayerNames[i]
]._legend
)
}
})(pxRGBA, i)
)
} else {
if (
L_.layers.data[IdentifierTool.activeLayerNames[i]]
?._legend
) {
value = bestMatchInLegend(
pxRGBA,
L_.layers.data[IdentifierTool.activeLayerNames[i]]
._legend
)
}
colorString =
'rgba(' +
pxRGBA.r +
',' +
pxRGBA.g +
',' +
pxRGBA.b +
',' +
pxRGBA.a / 255 +
')'
}

// prettier-ignore
liEls.push(
['<li style="margin: 4px 0px;">',
`<div style="display: flex;">`,
`<div style='width: 14px; height: 14px; margin-right: 8px; margin-top: 2px; background: ${colorString};'></div>`,
`<div style="letter-spacing: 0.5px; white-space: nowrap;">`,
d.name ||
L_.layers.data[
IdentifierTool.activeLayerNames[i]
].display_name,
`</div>`,
`</div>`,
`<div id='identifierToolIdPixelCursorInfo_${i}_${j}' style='padding-left: 20px;'>`,

(trueValue || value == null || value == '') ? [
'<div style="width: 100%; height: 22px; display: flex; justify-content: space-between;">',
'<div></div>',
'<div style="width: calc(100% - 4px); margin: 4px 4px 4px 0px; background: var(--color-a1);">&nbsp;</div>',
'</div>'].join('') : value,

`</div>`,
'</li>',
].join('')
)
}
colorString =
'rgba(' +
pxRGBA.r +
',' +
pxRGBA.g +
',' +
pxRGBA.b +
',' +
pxRGBA.a / 255 +
')'
}
liEls[i] =
"<li><div style='width: 14px; height: 14px; float: left; margin-right: 5px; margin-top: 1px; background: " +
colorString +
";'></div>" +
L_.layers.data[IdentifierTool.activeLayerNames[i]]
.display_name +
"<div id='identifierToolIdPixelCursorInfo_" +
i +
"' style='padding-left: 20px;'>" +
value +
'</div></li>'
}

CursorInfo.update(
htmlInfoString + liEls.join('') + '</ul>',
null,
Expand All @@ -368,9 +388,9 @@ var IdentifierTool = {
true
)

if (!trueValue) {
if (!trueValue && !selfish) {
IdentifierTool.mousemoveTimeout = setTimeout(function () {
IdentifierTool.idPixel(e, lnglatzoom, true)
IdentifierTool.idPixel(e, lnglatzoom, true, true)
}, 150)
}

Expand Down

0 comments on commit 15e966c

Please sign in to comment.