TransWikia.com

Regex for field name at ArcGIS JS API infoTemplate creation

Geographic Information Systems Asked by gregi1991 on November 28, 2020

I’m trying to make same dynamic content builder, but I’m not too experienced. This function sets the content for an infoTemplate of a sublayer(arcgisdynamicservice). It works well, if I hardcode the attribute field name like: graphic.attributes["SDE.SDE_ESRI_EP_FEATURECLASS_XX.FIELDNAME"]

I have never used regex in this type of app. Is it working at all, or did I miss something?

  function _getPopupTextContent(graphic) {
    let regex = /SDE.SDE_ESRI_EP_.*_XX.VALUE/;
    console.log(regex.test("SDE.SDE_ESRI_EP_FEATURECLASS_XX.FIELDNAME"));  
    //true      running when i'm clicking on the feature
    let popupContent = "<div style='padding:5px;background-color:rgb(251,183,46)'><b>" +
    "</b></div>" +
    "<table style='width:100%;'>"
      if (graphic.attributes[regex]){
        console.log("found") //not logging
        popupContent += "<tbody><tr><td id = 'attrtd'><b>AssetKKSCode</b></td><td id = 'attrtd''>" +
                          graphic.attributes[regex]
      }
      
        popupContent += "</td></tr>" +
                        "</td></tr>" +
                        "</a></td></tr>" +
                        "</tbody></table>"
    return popupContent;          
  }

One Answer

      function _getPopupTextContent(graphic) {       
    let popupContent = "<div style='padding:5px;background-color:rgb(251,183,46)'><b>" +
    "</b></div>" +
    "<table style='width:100%;'>"
    console.log(graphic.attributes)
    for (var property in graphic.attributes){
      var tableName = (property.toString()).split(/[_.]/)[4];
      var fieldName = (property.toString()).split(/[_.]/)[6];
        if(fieldName == 'FIELD1'){
          popupContent += "<tbody><tr><td id = 'attrtd'><b>Fieldname1</b></td><td id = 'attrtd''>" +
          graphic.attributes["SDE.SDE_ESRI_EP_"+tableName+"_MV."+fieldName]
        }
        if (fieldName == 'FIELD2'){
          popupContent += "<tbody><tr><td id = 'attrtd'><b>Fieldname2</b></td><td id = 'attrtd''>" +
          graphic.attributes["SDE.SDE_ESRI_EP_"+tableName+"_MV."+fieldName]
        }
    }
        popupContent += "</td></tr>" +
                        "</td></tr>" +
                        "</a></td></tr>" +
                        "</tbody></table>"
    return popupContent; 

So the regex was really unneeded for this, but i used it for proper slicing, and i made a variable for the tablename and for the fieldname. So i could check if the fieldname exists, but the name of the table doesn't matter when i check the object's props.

Answered by gregi1991 on November 28, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP