Select to view content in your preferred language

identify task being executed in a  loop, breaks the dojo deferred addCallback

1176
3
Jump to solution
07-12-2013 11:10 AM
NigelAlford
Occasional Contributor
I'm running a loop based on the currently visible layers to run an identify function for multiple layers simultaneously.  The identify task is working but I can't seem to get the deferred portion right.  I tried a .then vs addCallback but the return never updates the deferred object that the call is completed.  Any insight would be great.

idParams.geometry = evt.mapPoint;    idParams.mapExtent = map.extent;    var feature, lyrIdent = [];    for (var j = 0; j < ident.length; j++) {     if(ident.url != "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Reference/MapServer"){      deferred = ident[1].execute(idParams);     }     deferred.then(function(response){      return dojo.map(response, function(response){       var feature = response.feature;       lyrIdent.push(feature.attributes);       var template = new esri.InfoTemplate("#");       feature.setInfoTemplate(template);       return feature;      });     });    }    map.infoWindow.setFeatures([ deferred ]);    map.infoWindow.show(evt.mapPoint);    console.log(lyrIdent); }
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Take a look at this Fiddle, which returns the results from several different map services.

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor
Take a look at this Fiddle, which returns the results from several different map services.
0 Kudos
NigelAlford
Occasional Contributor
Thanks Ken.  I ended up solving this by creating an object literal, but I'm going to dig through your code, I like your organization and display method on the map.
0 Kudos
KenBuja
MVP Esteemed Contributor
I can't take credit for that example. I came across that posted somewhere on here or GIS.StackExchange and kept it as a bookmark. I'm not sure who coded it.
0 Kudos