Identify returns duplicate features

2666
5
Jump to solution
02-07-2012 10:10 AM
ShawnHolyoak
Occasional Contributor
I have an application that when I click identify, it looks at all layers in the map (over multiple services) and returns the results from all those services/layers.  I'm having strange behavior though, with one service.  It's returning duplicate values.  The other 3 services in the map all return correctly.  The services are all 9.3.1 services, and they are a mix of tiled and dynamic.  The idResults.length equals 6 when it should equal 3.  Any idea what could be going on? Code (thanks to http://forums.arcgis.com/threads/31757-Multiple-services-in-Identify-javascript-API?highlight=identi...) is below. Thanks.

function executeIdentify (loadedServices, evt) {  dojo.forEach(loadedServices, function(service) {   if (service.visibleLayers.length > 0) {                     expected_callback_counter++;                        //every visible layer should produce a callback, even if no results   }  }  );   //for each loaded non-base layer service  dojo.forEach(loadedServices, function(service) {                   //get service object            if (service.visibleLayers.length > 0 && service.visible) {              //does service have visible layers?          //showLoading();          url = service.url;                               //get url of service          identifyTask = new esri.tasks.IdentifyTask(url);    //ceate new identify task          identifyParams.layerIds = service.visibleLayers; //set layers to identify            identifyTask.execute(identifyParams,              function(idResults) {                           //callback function - fires for each visible layer                  if (idResults.length > 0) {                                           dojo.forEach(idResults, function(result) {         allResults.push(result);        }       );      }                                    callback_counter++;                         //a callback has fired - count them                                    if (callback_counter === expected_callback_counter) {                      if (allResults.length > 0) {                 //may have no results across all services        var content = "";        var currentLayerName;           for (var index = 0; index < allResults.length; index++) {         content += "<b>" + htmlEncode(allResults[index].layerName) + "</b><br>"             content += "<table>";             for (var member in allResults[index].feature.attributes) {          content += "<tr><td>" + htmlEncode(member) + ":</td><td>" +          htmlEncode(allResults[index].feature.attributes[member]) + "</td></tr>";         }            content += "</table><br>";        }           var resultText;        if (allResults.length === 1) {         resultText = " Feature Identified";        }  else {         resultText = " Features Identified";        }        map.infoWindow.setTitle(allResults.length + resultText);        map.infoWindow.setContent(content);        map.infoWindow.resize(320, 250);        map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));                      } else {                          alert('No results found!');                      }      }     },              //error callback              function(err) {console.log("doIdentify: (" + err.name + ") " + err.message);}         )    }   }  ) };
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
Instead of trying to manage multiple tasks (read:  deferreds) and their associated callbacks, try using a dojo.DeferredList. This has been discussed in the forums before in the context of both query tasks and identify tasks:  http://forums.arcgis.com/threads/37417-Match-asynchronous-response-to-original-request?p=129078&view...

When we release 2.7 (next version of the API), we'll be including a sample that shows how to do multiple query tasks and process the results once all query tasks return.

View solution in original post

0 Kudos
5 Replies
derekswingley1
Frequent Contributor
Instead of trying to manage multiple tasks (read:  deferreds) and their associated callbacks, try using a dojo.DeferredList. This has been discussed in the forums before in the context of both query tasks and identify tasks:  http://forums.arcgis.com/threads/37417-Match-asynchronous-response-to-original-request?p=129078&view...

When we release 2.7 (next version of the API), we'll be including a sample that shows how to do multiple query tasks and process the results once all query tasks return.
0 Kudos
ShawnHolyoak
Occasional Contributor
I will try and parse this and then refactor to take this approach.  Perhaps a sample for both query and identify at 2.7?  Thanks.
0 Kudos
derekswingley1
Frequent Contributor
I will try and parse this and then refactor to take this approach.  Perhaps a sample for both query and identify at 2.7?  Thanks.

We will likely stick with showing multiple query tasks because multiple identify tasks is essentially the same. The difference would be in what happens in the callback that fires when the deferredList is resolved.
0 Kudos
ShawnHolyoak
Occasional Contributor
We will likely stick with showing multiple query tasks because multiple identify tasks is essentially the same. The difference would be in what happens in the callback that fires when the deferredList is resolved.


Took me a bit of time to figure out how to make it work, but indeed, that resolved all issues I was having.  Thanks!
0 Kudos
derekswingley1
Frequent Contributor
Nice, happy to help!
0 Kudos