Arcgis JS API 3.x Popup infotemplate (popup) with relationship attributes

314
1
11-02-2020 12:31 AM
DávidGregor
New Contributor II

I've buildt a halfly harcoded popup builder widget, but i don't know how to push fields from relationships into my popup div. I know how to do it in the ObjOriented way, but it's not right for me. Example:

  ``` 

 var popupTemplate = new PopupTemplate({
 "title": "Beverly Hills Trees By Block",
 "fieldInfos": [{
 "fieldName": "Point_Count",
 "label": "Count of Points",
 "format": {
 "places": 0,
 "digitSeparator": true
 }
 }, {
 "fieldName": "relationships/0/Point_Count_COMMON",
 "label": "Sum of species tree count",
 "format": {
 "places": 0,
 "digitSeparator": true
 },

 ```

I show my scructure: first function creates the popup content div, the second calls it, if i want popup. But i couldnt find the documentation, how to get a graphic's relationships, i can only get the attributes. Any idea?

 ```
 function _getPopupTextContent(graphic) { 
 let popupContent = "" 
 popupContent += "<div style='padding:5px;background-color:rgb(251,183,46)'><b>" +
 "</b></div>" +
 "<table style='width:100%;'>"
 console.log(graphic)
 //popupContent += "<tr>"+graphic.attributes["relationships/1/FIELD"]+"</tr>" not working //undefined

 for (var property in graphic.attributes){
 console.log((property.toString()).split(/[.]/))
 var dbName = (property.toString()).split(/[.]/)[1]
 if (dbName !== undefined){
 var dbTableName = dbName.split(/[_]/)[3]; 
 //console.log(maximoTableName)
 var fieldName = (property.toString()).split(/[.]/)[2];
 let value = graphic.attributes["DB.DB_ESRI_V_"+dbTableName+"_TT."+fieldName]
 
 if(fieldName == 'FIELDNAME1'&& value !== undefined){
 popupContent += "<tbody><tr><td id = 'attrtd'><b>Label</b></td><td id = 'attrtd''>" +
 value
 }
 if(fieldName == 'FIELDNAME2'&& value !== undefined){
 popupContent += "<tr><td id = 'attrtd'><b>Label</b></td><td id = 'attrtd''>" +
 value
 }
 if(fieldName == 'FIELDNAME3'){
 popupContent += "<tr><td id = 'attrtd'><b>Label</b></td><td id = 'attrtd''>" +
 value
 }
 if(fieldName == 'FIELDNAME4'&& value !== undefined){
 popupContent += "<tr><td id = 'attrtd'><b>Label</b></td><td id = 'attrtd''>" +
 value
 }
 }
 popupContent += "</td></tr>" +
 "</td></tr>" +
 "</a></td></tr>" +
 "</tbody></table>"
 return popupContent; 
 }

 function _joinAndCreateInfoTemplate(){
 var mainLayer = _getWebmapOperationalLayerById(subStationLyrId);

 for(var title in popupSubIdDict){
 var popupName = _removeAccents(title).toLowerCase(); // subLayertitle
 var subId = popupSubIdDict[title]; //sub id

 mainLayer.getLayerObject().then(function (subLyrObj) {

 if (popupName == 'sublayer'){
 popupName = new InfoTemplate();
 popupName.setTitle(title);
 popupName.setContent(_getPopupTextContent);
 }

 subLyrObj.infoTemplates[subId] = {
 infoTemplate: new InfoTemplate(popupName)
 };




 ```
0 Kudos
1 Reply
DávidGregor
New Contributor II

So I'm trying to make a relationship query, but i run into an error: h.join is not a function.

what can be the problem? My related tables doesn't have objectId-s, they are just simply imported into the mxd.

      var layerList = [];
      var layerStructure = LayerStructure.getInstance();
        //No layer ID passed in, just get all layers.
        layerStructure.traversal(function(layerNode) {
            layerList.push(layerNode._layerInfo.layerObject);
        });
      console.log(layerList[14])
      let graphicAttributes = graphic.attributes
      
        let params = new RelationshipQuery();
        params.relationshipId1,
        params.outFields= ["*"],      
        params.objectIdsgraphicAttributes["alap_ep_PT.OBJECTID"]
        
        console.log(params)
        layerList[14].queryRelatedFeatures(params)
        .then(getResults)
        .otherwise(promiseRejected);
          function getResults(response) {
            console.log("results"response);
          }
          function promiseRejected(err) {
            console.error("Promise rejected: "err.message);
          }
        

layerList[14] is an object, it has a key, relationships:

  1. relationships: Array(2)
    1. 0: {id: 0, name: "DBNAME.ESRI_EP_TABLE_MV", relatedTableId: 39, role: "esriRelRoleOrigin", keyField: "DBNAME.TABLE.LOCATION", …}
    2. 1:
      1. cardinality: "esriRelCardinalityOneToMany"
      2. composite: false
      3. id: 1
      4. keyField: DBNAME.TABLE.LOCATION"LOCAT
      5. name: DBNAME.TABLENAME"
      6. relatedTableId: 38
      7. role: "esriRelRoleOrigin"
0 Kudos