AnsweredAssumed Answered

Identify returns duplicate features

Question asked by sholyoak on Feb 7, 2012
Latest reply on Feb 7, 2012 by DSwingley-esristaff
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=identify+multiple) 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);}         )    }   }  ) };

Outcomes