Even though this is an old post, I just want to say how much it helped me today. Absolutely outstanding! I did have to massage this code lightly to get it to work. I added some logic to only identify visible map service layers. Also, rather than creating a custom content box for the response, I was able to use map.infoWindow setFeatures and show methods to use the default map info window. Additionally, I tied it all to a map click event. Of course, I will need to take additional time to format info Templates for each layer. Here is my code:
map.on("click", function (event) {
let identifyParams = new IdentifyParameters();
identifyParams.tolerance = 3;
identifyParams.returnGeometry = true;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.mapExtent = map.extent;
identifyParams.geometry = event.mapPoint;
let callback_counter = 0;
let expected_callback_counter = 0;
dojo.forEach(loadedMapServices, function (service) {
let mapService = map.getLayer(service);
if (mapService.visibleLayers.length > 0) {
expected_callback_counter++;
}
});
let deferred = [];
dojo.forEach(loadedMapServices, function (service) {
let mapService = map.getLayer(service);
if (mapService.visible) {
if (mapService.visibleLayers.length > 0) {
let url = mapService.url;
let identifyTask = new IdentifyTask(url);
identifyParams.layerIds = mapService.visibleLayers;
let deferred_idTask = identifyTask
.execute(identifyParams)
.addCallback(function (response) {
return arrayUtils.map(response, function (result) {
let feature = result.feature;
let desc = result.layerName;
console.log(feature);
let Template = new InfoTemplate(desc, "${*}");
feature.setInfoTemplate(Template);
return feature;
});
});
deferred.push(deferred_idTask);
}
}
});
map.infoWindow.setFeatures(deferred);
map.infoWindow.show(event.mapPoint);
});
});