NazareneResearch

Popup information from two sources

Discussion created by NazareneResearch on Jun 12, 2012
Latest reply on Jun 14, 2012 by jgaa
I am trying to create a popup where I need to get information from two sources. I first need to get the key field from the point layer and then pass it to an API to get the rest of the information.  It is working except it is doing the "return feature;" line before the "feature.setInfoTemplate(template);" so my popup content is blank. When I debug it, it is getting the rest of the information successully but just not displaying it at the right time. How do I get it to set the information before it returns the feature.

Code:
      function executeIdentifyTask(evt) {
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
      
        var contactInfo = identifyTask.execute(identifyParams);
       
        contactInfo.addCallback(function(response) {    
          return dojo.map(response, function(result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            if (result.layerName === 'NazCh'){
              var url = esri.urlToObject("http://app.naz.org/OrgContactInfoAPI/v1.0/" + result.feature.attributes.WKEY);
              var requestHandle = esri.request({
                url: url.path,
                content: url.query,
                load: function(resultOpal, io){
                  var template = new esri.dijit.PopupTemplate({
                    title: resultOpal.orgName,
                    fieldInfos: [{
                      fieldName: "resultOpal.districtName",
                      visible: true,
                      label: "District"
                    }, {
                      fieldName: "resultOpal.preferredLanguageName",
                      visible: true,
                      label: "Language"
                    }]
                  });
                  feature.setInfoTemplate(template);
                }
             },{useProxy:true});
              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([ contactInfo ]);
        map.infoWindow.show(evt.mapPoint);
      }

Outcomes