Building and executing IdentifyTask

IdentifyTask can operate on multiple layers in a map service and fetch information from all the features intersecting with a given geometry. We will use IdentifyTask to click on the map and get the value of the wildfire potential at the clicked location. To execute IdentifyTask, we need to follow three steps:

  1. Instantiate IdentifyTask.
  2. Construct the Identify parameters.
  3. Execute IdentifyTask.

Instantiating IdentifyTask

Instantiating IdentifyTask involves loading the required module and instantiating it with a map service URL. The modules required for executing IdentifyTask are the following:

  • esri/tasks/IdentifyTask
  • esri/tasks/IdentifyParameters

We will be operating IdentifyTask on the Wildfire Potential Map service. The map service contains a single raster layer and pixel values representing wildfire potential levels. The following snippet shows how IdentifyTask is instantiated:

varwildfirePotentialURL = "http://maps7.arcgisonline.com/arcgis/rest/services/USDA_USFS_2014_Wildfire_Hazard_Potential/MapServer";
varidentifyTask = new IdentifyTask(wildfirePotentialURL);

Constructing the identify parameters object

Identify parameters provides a lot of properties to define the identify operation being performed. While dealing with multiple layers, we can restrict the layers upon which identify can be performed by using the layerIds property. The geometry property lets us set the geometry that is used to select features in the map service upon which identify operates. In our application, we are using the map click point as the input geometry for the IdentifyParameter. When using a point geometry, we also need to define the value for the tolerance property in the IdentifyParameters. The tolerance value refers to the number of pixels around the input point geometry that can be considered as part of the input geometry.

In the following screenshot, we construct an identify parameter object, which is wrapped around by the map click event handler. The mapPoint property of the map click event handler provides the input geometry for the identify operation:

Constructing the identify parameters object

Executing IdentifyTask

The execute() method of IdentifyTask can be used to execute the task. The execute() method returns the Deferred object, and the success callback of the Deferred object returns the IdentifyResult array object.

An identify result represents a single identified feature from one of the layers in the map service. The object has the following properties:

  • displayFieldName: This is the name of the layer's primary display field
  • feature: A feature object contains an array object and a geometry object
  • layerId: This is the unique ID of the layer that contains the feature
  • layerName: This is the name of the layer

Since the identify result is an array object, and we are only showing one value, we will be taking only the first value from the identify result object (result[0]), as shown in the following screenshot. The value that we need to show is in an attribute field named CLASS_DESC. Since this value is prefixed by a class code separated from the class description by a colon (:) (for example, 5: Very High), we will be separating the string based on the colon and use the description part alone.

The following screenshot shows the code that is used to perform the identify operation as well as showing the identify result as a label for the map click location, which is represented by a pointer cursor:

Executing IdentifyTask
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.116.43