AnswerBun.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!

Related Questions

Merge with custom method in rasterio

1  Asked on December 30, 2020 by capooti

 

Does QGIS use data source-specific operations?

0  Asked on December 30, 2020 by geotob

     

Writing Non Spatial Table into Geopackage – Python

2  Asked on December 30, 2020 by jamesleversha

       

GeoServer blocked HTTP requests issue

1  Asked on December 30, 2020 by peterzhu

 

Displaying map title in PyQGIS

1  Asked on December 29, 2020 by marcelo-freitas

         

Cancel event in Python Gp tools with arcpy

3  Asked on December 29, 2020 by user17515

   

Center Text In Table Column

3  Asked on December 29, 2020 by slywhitesheep

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir