ArcGIS JavaScript API: Understanding the Query Task


The Query Task is probably the single most important class in the ArcGIS Server Javascript API. Understanding how to access data from the server and how to manipulate it is the cornerstone to developing any GIS application.

There are a few examples within ESRI’s sample page, however I wanted to provide two examples outlining how I use the Query Task on a regular basis.

Example #1 shows how to use the Query Task’s where clause and pull data directly from a map service. ESRI’s provides a similar example, however it requires the user to submit a query within the page. My example allows you to have the query pre-canned and the results load with the page.

Example #2 takes this a step further and introduces the ability to access the same functionality via POST or GET. This is perfect for anyone interested in loading data into the page via URL variables (example2.php?name=Idaho) or perhaps someone that would like to call this function via AJAX.

I use example #2 all the time, so hopefully you’ll find it as useful as I do.

DOWNLOAD: EXAMPLES 1 & 2

*All data is provided via ESRI’s hosted map services. Example 2 requires PHP.

,