From 15e966c514e00e4a9025b85b0661cb523f56f3ee Mon Sep 17 00:00:00 2001 From: tariqksoliman Date: Thu, 14 Dec 2023 18:59:42 -0800 Subject: [PATCH] #473 Layer Specific IdentifierTool vars 1 --- src/essence/Basics/Layers_/Layers_.js | 14 +- .../Tools/Identifier/IdentifierTool.js | 254 ++++++++++-------- 2 files changed, 149 insertions(+), 119 deletions(-) diff --git a/src/essence/Basics/Layers_/Layers_.js b/src/essence/Basics/Layers_/Layers_.js index 76f8e987..2d58c4f6 100644 --- a/src/essence/Basics/Layers_/Layers_.js +++ b/src/essence/Basics/Layers_/Layers_.js @@ -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.` diff --git a/src/essence/Tools/Identifier/IdentifierTool.js b/src/essence/Tools/Identifier/IdentifierTool.js index 27a86c33..fd4f329f 100644 --- a/src/essence/Tools/Identifier/IdentifierTool.js +++ b/src/essence/Tools/Identifier/IdentifierTool.js @@ -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 @@ -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 @@ -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) @@ -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( + [ + '
', + '
', + '
 
', + '
', + ].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 += + '
' + + value[v][0] + + '
' + + valueParsed + + '
' + cnt++ + } + $( + `#identifierToolIdPixelCursorInfo_${i}_${j}` + ).html(htmlValues) } - var valueParsed = - parseValue( - value[v][1], - IdentifierTool.vars[ - IdentifierTool.activeLayerNames[ - i - ] - ].sigfigs - ) + - '' + - unit - htmlValues += - '
' + - value[v][0] + - '
' + - valueParsed + - '
' - 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( + ['
  • ', + `
    `, + `
    `, + `
    `, + d.name || + L_.layers.data[ + IdentifierTool.activeLayerNames[i] + ].display_name, + `
    `, + `
    `, + `
    `, + + (trueValue || value == null || value == '') ? [ + '
    ', + '
    ', + '
     
    ', + '
    '].join('') : value, + + `
    `, + '
  • ', + ].join('') + ) } - colorString = - 'rgba(' + - pxRGBA.r + - ',' + - pxRGBA.g + - ',' + - pxRGBA.b + - ',' + - pxRGBA.a / 255 + - ')' } - liEls[i] = - "
  • " + - L_.layers.data[IdentifierTool.activeLayerNames[i]] - .display_name + - "
    " + - value + - '
  • ' } + CursorInfo.update( htmlInfoString + liEls.join('') + '', null, @@ -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) }