I m executing identify task on multiple services,thus getting results of all services, i want to combine all results to show in a infowindow.
map.on('click',function(event){
var identify_result=[];
var resultDef=[];
var callback_counter=0;
var deferred;
var counter_res=0;
map.setCursor("Default");
if(viewData_clicked){
var def = new dojo.Deferred();
dojo.forEach(layerInfo,function(id){
var url = map.getLayer(id).url;
identifyTask = new IdentifyTask(url);
identifyParams = new IdentifyParameters();
identifyParams.tolerance=10;
identifyParams.returnGeometry = true;
identifyParams.layerIds = map.getLayer(id).visibleLayers;
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.geometry = event.mapPoint;
identifyParams.mapExtent = map.extent;
deferred = identifyTask
//identifyTask
.execute(identifyParams)
.addCallback(function (response) {
console.log("response",response);
return arrayUtils.map(response, function (result) {
var feature = result.feature;
var layerName = result.layerName;
// map.infoWindow.setTitle(layerName);
var content = "<tr bgcolor='grey'><th><b>Field Name</b></th><th><b>Value</b></th></tr>";
$.each(feature.attributes,function (key,value){
content +="<tr><td>"+ key+"</td><td><b>"+value+"</b></td></tr>";
});
// map.infoWindow.setContent("<table border='1'>"+content+"</table>");
var infotemplate = new InfoTemplate(layerName,"<table border='1'>"+content+"</table>");
feature.setInfoTemplate(infotemplate);
return feature;
});
});//execute
callback_counter++;
identify_result.push(deferred);
}); //forEach
//if(layerInfo.length === callback_counter){
//var def = identifyTask.execute();
var res_features=[];
dojo.require("dojo.promise.all");
dojo.forEach(identify_result,function(i){
counter_res++;
var def = dojo.promise.all()
def.then(function(result) {
//res=result;
dojo.forEach(result,function(element){
dojo.forEach(element,function(j){
res_features.push(j);
});
});
if((identify_result.length === counter_res) && (res_features.length > 0) ){
console.log("identify_result.length",identify_result.length);
console.log("counter_res",counter_res);
console.log("result",result);
console.log("res_features",res_features);
var defrd = new dojo.Deferred();
defrd = deferred;
defrd.results=res_features;
console.log(defrd);
//map.infoWindow.setFeatures([defrd]);
//map.infoWindow.show(event.mapPoint);
}
});
});