Book Image

Building Web and Mobile ArcGIS Server Applications with JavaScript ??? Second Edition - Second Edition

By : Eric Pimpler, Mark Lewin
Book Image

Building Web and Mobile ArcGIS Server Applications with JavaScript ??? Second Edition - Second Edition

By: Eric Pimpler, Mark Lewin

Overview of this book

The ArcGIS API for JavaScript enables you to quickly build web and mobile mapping applications that include sophisticated GIS capabilities, yet are easy and intuitive for the user. Aimed at both new and experienced web developers, this practical guide gives you everything you need to get started with the API. After a brief introduction to HTML/CSS/JavaScript, you'll embed maps in a web page, add the tiled, dynamic, and streaming data layers that your users will interact with, and mark up the map with graphics. You will learn how to quickly incorporate a broad range of useful user interface elements and GIS functionality to your application with minimal effort using prebuilt widgets. As the book progresses, you will discover and use the task framework to query layers with spatial and attribute criteria, search for and identify features on the map, geocode addresses, perform network analysis and routing, and add custom geoprocessing operations. Along the way, we cover exciting new features such as the client-side geometry engine, learn how to integrate content from ArcGIS.com, and use your new skills to build mobile web mapping applications. We conclude with a look at version 4 of the ArcGIS API for JavaScript (which is being developed in parallel with version 3.x) and what it means for you as a developer.
Table of Contents (21 chapters)
Title Page
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Executing the query with QueryTask


Once you've defined the nature of the query in a Query object you can then use QueryTask to execute the query.

First, create an instance of the QueryTask object. You create a QueryTask object by passing the URL of the layer against which the query will be executed to its constructor. Note from the code example that follows that the map service URL includes an index number which references a specific layer in the map service which will be queried:

myQueryTask = new 
QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_CENSUS_USA/MapServer/5"); 

Once you have created the QueryTask object you can perform a query against its layer passing a Query object to its QueryTask.execute() method.

QueryTask.execute() accepts three parameters: the Query object, a function to call when the operation succeeds, and a function to call if the operation fails.

The syntax for QueryTask.execute() is provided as follows:

QueryTask.execute(objQuery...