Asynchronous query calls

1313
3
Jump to solution
05-28-2012 11:04 PM
AndrewLeane
New Contributor II
Hi all,

I'm still a newbie with the Javascript API, but my issue seems very similar to one solved on the Flex API forum. I am running multiple queries, and I need to know which layerId the resulting featuresets come from. As the results are asynchronous, I'm not sure which featureset comes from which layer.

The solution on the Flex forum was:

Add the reference to your layer when you do the query like:  queryTask.execute(query, new AsyncResponder(onResult, onFault, myLayerID));  Then define your result handler like :  function onResult(featureSet:FeatureSet, myLayerID:Number):void { ... }


is there a way to do a similar thing in javascript by creating a new AsyncResponder?

Thanks very much
Andrew
0 Kudos
1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor
0 Kudos
3 Replies
YohanBienvenue
Occasional Contributor II
Hi all,

I'm still a newbie with the Javascript API, but my issue seems very similar to one solved on the Flex API forum. I am running multiple queries, and I need to know which layerId the resulting featuresets come from. As the results are asynchronous, I'm not sure which featureset comes from which layer.

The solution on the Flex forum was:

Add the reference to your layer when you do the query like:

queryTask.execute(query, new AsyncResponder(onResult, onFault, myLayerID));

Then define your result handler like :

function onResult(featureSet:FeatureSet, myLayerID:Number):void
{
...
}


is there a way to do a similar thing in javascript by creating a new AsyncResponder?

Thanks very much
Andrew



If the API doesn't provide it to you, I guess you could manually pass the layerId to your callback yourself.
Maybe something like this could work:

function callback(featureset, layerId){
...
}
 
var _this = this;

var query = new esri.tasks.Query();
query.where = "STATE_NAME = 'Washington'";
query.outSpatialReference = {wkid:102100}; 
query.returnGeometry = true;
query.outFields = ["CITY_NAME"];
queryTask.execute(query, function(featureset){ _this.callback.call(_this, featureset, 12); });

.....

queryTask.execute(query, function(featureset){ _this.callback.call(_this, featureset, 14); });

......

etc

0 Kudos
nicogis
MVP Frequent Contributor
0 Kudos
AndrewLeane
New Contributor II
Thanks Yohan and Domenico, I used the dojo.deferredList - it's a nice neat way to keep track of the order of the queries. I'll have to remember to check all the samples, not just the API.
Thanks again.
0 Kudos