Performing different QueryTasks depending on zoom

Discussion created by ali7789v4 on Mar 24, 2011
Latest reply on Mar 28, 2011 by ali7789v4

I have a MSD file that changes layers as you zoom in, so more detail is revealed as you zoom in closer to the ground.

The MSD contains several layers which are vectors. I want to have a buffer query task for the user to query the data for each layer. However, I realise I need to have a query task for each layer of vectors and having only ever worked with one query task in the past, what is the best way to do this?

So far, I haven't been able to get this working.

I am using "onExtentChange" to get the zoom level, but for some reason if I update a global variable when the extent changes, the query task stops working - almost as if it crashes, but no error messages. I'd like to do something like this:
    queryTask = new esri.tasks.QueryTask("http://gis-server/ArcGIS/rest/services/MSDFile/MapServer/"+layer);
... where layer is the layer number.
But despite it being a global var, the query task doesn't work!

I've also tried declaring seperate query tasks for each layer in the init() function, but then that creates problems when you need to refer to them. I've tried eval() to incorporate the layer id but it doesn't always work.

Can someone either point me to an example online where this happens or help me understand the best approach to getting this working?