Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This applies to ArcGIS Server 9.3 with the JavaScript API 2.4.

My goal is to click on the map and have the Identify task run on all visible Dynamic layers.

IdentifyTask requires a URL to the REST endpoint, with IdentifyParameters specifying which layerIds the identify operation should be performed on.

It seems the Identify tool is expecting all layers to be accessible from the same REST endpoint (ie, the same ArcGIS Server).

In my case, layers are being served from multiple ArcGIS Server instances - how can the Identify tool support this? For example, if the Buildings and Parcels layers in this map were coming from separate ArcGIS Servers.

(This is related to my previous question, but I realise now I need to answer this question first)

share|improve this question
    
Has there been any updates to these concepts? I have been using the fiddle sample referenced above. Thanks –  phase Feb 1 '12 at 20:26
    
@phase as far as I know the concepts are still the same using ArcGIS Server 10 and JS API 2.6, assuming that's what you mean –  Stephen Lead Feb 1 '12 at 22:41

3 Answers 3

up vote 8 down vote accepted

First, here is a simplified JavaScript API example to show the concept of using DeferredList to process multiple identify tasks:

//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.IdentifyParamaters.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
}

Then here is an example in jsFiddle that I think does what you want, runs using all visible layers in all visible dynamic map layers in the map.

http://jsfiddle.net/blordcastillo/mULcz/

All typos are fixed now :)

The basic idea is that whenever the map is clicked or visibility is toggled, the identify is rerun. When the identify is run, the number of identity tasks fired depends on the number of layers visible, and it waits until all layers return to display its results.

share|improve this answer
    
that makes a lot of sense - thanks so much for posting the sample code –  Stephen Lead Jul 27 '11 at 4:33
1  
There are a couple of tiny typos in your code - which is actually more impressive as it implies you typed this from memory and didn't even need to run it. Hats off to you! –  Stephen Lead Jul 29 '11 at 6:05
    
Yes, I did just type that off the top of my head :) Let me know what the minor typos are and I will fix them. –  blord-castillo Jul 29 '11 at 12:35
    
Changed to a working version in jsFiddle. The version is not perfectly efficient; ideally I would save my query results and just redo the showResults section when visibility is toggled by the identify point is not changed. But, I think it shows the concept well of how to tie the visibility toggling together with the identify tasks executed. Also, you would want to store a template with each layer so you can just pull the templates off the layers, rather than using logic inside the javascript functions like I did. –  blord-castillo Jul 29 '11 at 17:01

I recreated this very scenario with deferred list, but the tricky part was only identifying on layers that are in scale. This is for version 3.2 jsapi http://www.spatialexception.org/posts/arcgis-javascript-identifytask-returns-scale-dependent-layers

share|improve this answer
    
nice one, thanks for sharing –  Stephen Lead Nov 19 '12 at 22:47
    
@awesomo, any chance of seeing the live link to this solution? –  Scott Jan 3 at 18:04
    
There is an i identify icon on the upper right of toolbar mapserver2.vestra.com/demo/smile –  awesomo Jan 6 at 15:08

The identify task can only reference one map service, so you will have to either:

  • Put all the layers you wish to run Identity on in one map service
  • Run multiple IdentifyTasks per map click

I ran into a similar situations with an app where I wanted to be able to identify on a DEM map service, and on a sea level rise result map service from a geoprocessing task. I chose to run two IdentifyTasks. The only thing you really have to add is figuring out when both tasks are done.

The basic flow is (this was using Silverlight/C#)

  • setup boolean variables for DEM and SLR identifyTaskcomplete
  • Run IdentifyTask for DEM
  • set bool for DEMidentifyTaskComplete to false
  • Run IdentifyTask for SLR (using same general parameters as for DEM)
  • set bool for SLRidentifyTaskComplete to false
  • In DEMIdentifyTask_ExecuteCompleted event listener, I set DEMidentifyTaskcomplete to true and then check to see if SLRidentifyTaskcomplete is true (set up the opposite for SLRIdentifyTask_ExecuteCompleted)
  • Whichever task finished last, both bools will be true, and calls IdentifyTasksComplete which parses both results into a custom graphic object which I add to the map, then set slr and demidentiftytaskcomplete to false
share|improve this answer
    
thanks - that's what I feared, but it's good to hear that you found it workable. If this site is available, can you please let me know the URL? –  Stephen Lead Jul 20 '11 at 22:53
    
It's not public, and is in Silverlight besides. Good luck! –  wwnick Jul 21 '11 at 0:17
    
+1 for multiple identify tasks. For the JavaScript API, you can manage them with dojo.DeferredList (also applies to multiple queryTasks). –  Derek Swingley Jul 23 '11 at 0:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.