[GIS] ArcGIS JS API Relationship Queries

arcgis-javascript-apijavascriptrelates

Has anyone ever put the results of a RelationshipQuery() into a map.infoWindow that's been replaced with a dijit.popup?

Here's the workflow:
User clicks a point, and all identify results are put into popup. <–this part is fine

I'm struggling with calling a relationshipquery, then putting the results into the infoTemplate.

The function findRelatedRecords performs 3 relationship queries and assembles an array of objects that are related to the single point. I cannot get this data back into the executeIdentifyTask function.

The function getWindowContent takes the relationshipquery array and converts it to html and constructs a dijit.tabcontainer & 2 contentpanes (tabs). It return the tabcontainer.domNode.

Any help? I'm really struggling!!

function executeIdentifyTask(evt) {
    facSel.clearSelection();
    identifyParams.geometry = evt.mapPoint;
    identifyParams.mapExtent = map.extent;

    var deferred = identifyTask.execute(identifyParams);

    deferred.addCallback(function(response) {

      // response is an array of identify result objects    
      // Let's return an array of features.
      return dojo.map(response, function(result) {
        var feature = result.feature;
        console.log(result);
        //feature.attributes.layerName = result.layerName;
        if(result.layerName === 'parcel_area2'){
          //console.log(feature.attributes.site_code);
          var template = new esri.InfoTemplate("", "${site_code} <br/> Owner of record: ${facil_loca}");
          feature.setInfoTemplate(template);
        }
        else if (result.layerName === 'logistics2'){
          var template = new esri.InfoTemplate("", "Parcel ID: ${Type}");
          feature.setInfoTemplate(template);
        }
        else if (result.layerName === 'query2'){
            findRelatedRecords(feature,evt) //<--get relationship query results here    
            var template = new esri.InfoTemplate("", getWindowContent(data,evt.graphic));
            feature.setInfoTemplate(template);          

        }
        return feature;
      });
    });
    // InfoWindow expects an array of features from each deferred
    // object that you pass. If the response from the task execution
    // above is not an array of features, then you need to add a callback
    // like the one above to post-process the response and return an
    // array of features.
    map.infoWindow.setFeatures([ deferred ]);
    map.infoWindow.show(evt.mapPoint);

  } 

Best Answer

I did the following:

dojo.map(response, function (result){
    if (result.layerName === 'mylayer') {
    var relInfo = '';
    // create a new InfoTemplate, and set the title
    var template=new esri.InfoTemplate('Template','${*}');
    template.setTitle('myTitle');
    // create the RelationshipQuery
    myFeatureLayer.queryRelatedFeatures(relQuery, function(relRecords){
        // build a string of related info
        relInfo = relRecords['myKey'].features[0].attributes['myAttribute'];
    }).then(function() {
        // using the string of related info, setContent for the InfoTemplate here.
        template.setContent(relInfo);
    });
}

And I had to use a timeout to call setFeatures, otherwise the first result of multiple was always blank (the length of the timeout depends on how much related data is being returned):

setTimeout(function() { map.infoWindow.setFeatures([deferred]); }, 1000);
Related Question