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.

How can a queryTask be executed synchronously? I'd like a feature set to be returned instead of deferred object. Thanks,

share
    
I use queryTask.execute in a cycle because I search all features from several layers that are found inside some rectangle.So I run by layers and for each layer call queryTask.execute and in callback function in its parameter "results" I get some feature set. Because this object does not contain corresponding layer id I'd like to create a new object that contains layer id and feature set. So I need callback function work synchronously. I tried your advice but this does not help: firstly the cycle is ended and only after that the callback or onComplete or .then of deferred begin to work (also in –  Evgeny Jun 15 at 13:44

1 Answer 1

In instances like this, the API returns deferred objects in case you're interested in identifying when more than one request to a server has resolved, but its not something your application logic has to worry about if you're just dealing with one task at a time.

for example, when you call QueryTask.execute() and leverage the in-built callback, you can get a reference to the featureset output you want:

queryTask.execute(query, myCallback, myErrorBack);
...
myCallback(results) {
  //do something
}

To work with QueryTask deferreds, you have an additional option to do something like this:

var myDeferred = queryTask.execute(query);
myDeferred.then(...
share
    
Thanks, that makes sense however, I need to create a function/(web service?) that returns a feature set. The callback function performs a task, but I need to return a result, not a promise. How would you go about that? –  Matej May 13 at 21:00
    
sorry, but i'm not sure what youre talking about. –  John Gravois May 14 at 18:15
    
Let me try to rephrase.. If I return a result of a queryTask, I get a promise. Let's say I have a function called myFunction that performs a queryTask based on a polygon geometry. The function call would look something like: var result = myFunction(myGeometry, myMapServiceUrl); Since the function returns before the queryTask completes, the result is of promise type. Perhaps, I need to treat the result as it was an actual featureSet? –  Matej May 14 at 18:44

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .