Select to view content in your preferred language

How to perform multiple querytasks?

732
3
03-23-2011 10:32 AM
DonKang
Regular Contributor
I would like to perform series of querytasks.
Based on the first query results, I would like to perform a second query.
And when second query is complete, I would like to show the results in a popup window.

Attached example do seemed to work, but behaves little weird.
I've added Alert to the script.
On a first map click to select a state, everything seems to work correctly. And I get one alert notice.
On my next map click to select another state, again things seems to work correctly, but this time I get about 4 alerts. Value of previous selection gets displayed on the info window.
On my third map click, I get about 10 alert popups.

Looks like the querytasks that I have setup somehow remembers all the previous queries and loops through whenever I do mouse click on the map.
Can anyone see why this is happening???

thanks

Don Kang
0 Kudos
3 Replies
derekswingley1
Deactivated User
There are a few things to fix but the main one is how you're assigning callback functions for your query tasks. Since you're re-using global variables for your query tasks, each time showResults() is called, a new callback is attached to your query task. To avoid this, I'd recommend passing in a function for the callback argument of queryTask.execute() instead of using dojo.connect to add a new callback each time showResults() runs. Take a look at the attached code to see how this is done.

The other big change I made was to use a new global to keep track of the current map click (variable named "currentClick").

I also took out your bClick variable as it seemed unnecessary (but maybe I'm missing something).
0 Kudos
DonKang
Regular Contributor
Derek,
thank you very much for your help.
I started off doing something very similar to your fix before I went with dojo.connect
option. Yours definitly works.
I've received ESRI's help and their solution was to implement dojo.disconnect option at the end of function. Which also seems to work very good as well.
Now I have two different options, I will just test both and see which one renders the map faster.

Sorry for late response, in old days, I used to get notification email when someone replys my message.
Thanks again for your help.

Don

There are a few things to fix but the main one is how you're assigning callback functions for your query tasks. Since you're re-using global variables for your query tasks, each time showResults() is called, a new callback is attached to your query task. To avoid this, I'd recommend passing in a function for the callback argument of queryTask.execute() instead of using dojo.connect to add a new callback each time showResults() runs. Take a look at the attached code to see how this is done.

The other big change I made was to use a new global to keep track of the current map click (variable named "currentClick").

I also took out your bClick variable as it seemed unnecessary (but maybe I'm missing something).
0 Kudos
derekswingley1
Deactivated User
Glad you got it worked out!
0 Kudos