AnsweredAssumed Answered

Deferreds and Identify Task

Question asked by HandsomePete on May 28, 2013
Latest reply on Jan 29, 2015 by Mr_Kirkwood
Asynchronous programming newbie question.  I need to run an identify task on a dynamic map service layer.  After I get the results of the identify, I need to do another operation before the results are sent to the popup.  I'll use that operation to format the infoTemplate.

How do I prevent the popup from displaying until I format it?  It seems that as soon as the result comes back, the dojo will display the popup with the returned records.  I think I need to chain the deferreds or create a deferred list, but I can't grok how it works.


function executeIdentifyTask(evt) {
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;
       if(result.layerName === 'Tax Parcels'){
if (blah.length>0) {
  FORMAT CONTENT HERE
          var template = new esri.InfoTemplate("", "${Postal Address} <br/> Owner of record: ${First Owner Name}");
          feature.setInfoTemplate(template);
}
else
{
  FORMAT CONTENT DIFFERENT WAY HERE
          var template = new esri.InfoTemplate("", "${Different Stuff} <br/> Owner of record: ${Blah}");
          feature.setInfoTemplate(template);
}
});
        console.log(feature.attributes.PARCELID);
       }
       else if (result.layerName === 'Building Footprints'){
        var template = new esri.InfoTemplate("", "Parcel ID: ${PARCELID}");
         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);
      }

Outcomes