Select to view content in your preferred language

Performing different QueryTasks depending on zoom

793
4
03-24-2011 03:27 AM
AlistairDorman-Smith
Emerging Contributor
Hi

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?

Thanks
0 Kudos
4 Replies
derekswingley1
Deactivated User
Sounds like you're on the right track but forget about eval(), I don't think that is the answer to your problem.

Can you post a more complete code sample so we can see exactly what you're doing?
0 Kudos
AlistairDorman-Smith
Emerging Contributor
Thanks for your reply. I have attached an example of a very basic script that doesn't work. Unfortunately it's not on a public webserver so I can't show a real example.

If I comment out the one line within the function setQueryLayer() then it works (using the default) query task on every zoom level, it's just it will always use layer 4. This appears to be where the problem happens.

Looking in Firebug, I can see that the POST requests (via the proxy) go from a second or two to milliseconds when the queries start failing, so I don't know if this is significant.

At the highest level, the map that appears has vectors split into the UK government office regions, e.g. "north east", "scotland", "north west". As you zoom down, they split into local authorities etc. Another strange problem I have - maybe related - is that if at the highest level, I click within Scotland to do a 10K buffer search (well within the vector boundaries), it takes 40 seconds to do the POST query and then completely crashes my browser. No idea why!

I should also say this is querying vectors, not point sources (although I want to add a second query task in later down the line to query a point source layer, but that's for later, I need to get this working first!)

I'm new to the JS API, so you may find my code isn't the best!

Thanks for any help you can provide.
0 Kudos
derekswingley1
Deactivated User
Let's stick with your query issues first.

I've looked through your code and don't see where something would be going wrong unless the urls to your layers are off. This is what the code is generating for me:
http://gisserver/ArcGIS/rest/services/Mapping_MSD/MapServer/3
http://gisserver/ArcGIS/rest/services/Mapping_MSD/MapServer/2
http://gisserver/ArcGIS/rest/services/Mapping_MSD/MapServer/1

Are those urls to the layers you want to query? And do they all have a field named "Total"?
0 Kudos
AlistairDorman-Smith
Emerging Contributor
Hi, thanks for getting back to me.

I have found the reason why this is failing - it appears for it to work, I have to disconnect the event handlers and then reconnect them each time the zoom level changes.

Not entirely sure why, nor can I see anything on the ESRI dev centre that would point to this, but I found this through trial and error!

It's working now, which is the main thing.

Thanks for your time helping.
0 Kudos