首先,这是一个简化的JavaScript API示例,显示了使用DeferredList处理多个标识任务的概念:
//Assume that map is your map object
var idTask1, idTask2, idParams = new esri.tasks.IdentifyParameters();
var url1 = "<server1 url>", var url2 = "<server2 url>";
dojo.connect(map, "onLoad", initIdentifies);
function initIdentifies(map) { //map.onLoad passes in the map object
idTask1 = new esri.tasks.IdentifyTask(url1);
idTask2 = new esri.tasks.IdentifyTask(url2);
//A few sample constant parameters. Set more or less as you need
idParams.tolerance = 12;
idParams.returnGeometry = true;
idParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
dojo.connect(map, "onClick", runIdentifies);
}
function runIdentifies(evt) {
var defTask1 = new dojo.Deferred(), defTask2 = new dojo.Deferred;
var dlTasks = new dojo.DeferredList([defTask1, defTask2]);
dlTasks.then(showResults); //defTasks will fire after defTask1 and defTask2 have completed
//These parameters change with each request
idParams.width = map.width;
idParams.height = map.height;
idParams.geometry = evt.mapPoint;
idParams.mapExtent = map.extent;
try {
idTask1.execute(idParams, defTask1.callback, defTask1.errback); //Pass the response into the callback on defTask1
} catch (e) {
console.log("Error caught");
console.log(e);
defTask1.errback(e); //If you get an error, execute the errback
}
try {
idTask2.execute(idParams, defTask2.callback, defTask2.errback); //Pass the response into the callback on defTask2
} catch (e) {
console.log("Error caught");
console.log(e);
defTask2.errback(e); //If you get an error, execute the errback
}
}
function showResults(r) {
//The format of 'r' is [[Boolean task 1 success, [task 1 results]],[Boolean task 2 success, [task 2 results]]]
//using the array 'r', build and show your infoWindow as normal
}
然后这是jsFiddle中的一个示例,我认为您可以执行所需的操作,并使用地图中所有可见动态地图图层中的所有可见图层运行。
http://jsfiddle.net/blordcastillo/mULcz/
现在,所有错别字都已解决:)
基本思想是,每当单击地图或切换可见性时,都会重新运行标识。运行标识时,触发的身份任务的数量取决于可见的层数,并且等待直到所有层返回以显示其结果。