Using the IdentifyTask with a WebMap from AGOL with the 4.x API

527
6
Jump to solution
05-04-2017 09:53 AM
TomFlahive
New Contributor III

I have an ArcGIS Online WebMap with 5 web services on it and I would like to run an IdentifyTask so that I can obtain a list of all the features that fall under a clicked point.  I know that popups provide this same functionality of being able to identify all the features under a clicked point, but I am looking to present the data in a custom sidebar rather than a popup, so I figured using the IdentifyTask is the way to go. 

A similar question has been asked and answered (by Kelly Hutchins) on how this might be done with the 3.x API (here), but I am trying to figure out how to do it with the 4.x API.

The part I am stuck on is what to pass in to the IdentifyTask in place of a service URL, as shown in the Esri example:

// Create identify task for the specified map service
identifyTask = new IdentifyTask(mapServiceURL);

Can the IdentifyTask be used with an AGOL WebMap, and if so, what needs to be done to accomplish that?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Tom,

   That would be as simple as:

// get the first layer in the collection of operational layers in the WebMap
// when the resources in the MapView have loaded.
var featureLayer = webmap.layers.getItemAt(0);‍‍‍
identifyTask = new IdentifyTask(featureLayer.url);

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Tom,

   That would be as simple as:

// get the first layer in the collection of operational layers in the WebMap
// when the resources in the MapView have loaded.
var featureLayer = webmap.layers.getItemAt(0);‍‍‍
identifyTask = new IdentifyTask(featureLayer.url);

View solution in original post

TomFlahive
New Contributor III

Thanks Robert.  I didn't know it would just be a matter of pulling each individual URL.  I was thinking there would be a way to pass in all the layers from the WebMap at once. 

So if I want to pull the data back for all 5 services on the WebMap, then I would just iterate through the layers and create a separate identify task for each one, correct?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tom,

   The thing to look out for is the IdentifyTask is looking for the mapservice url and not an individual layer url (i.e. http //servername/arcgis/rest/services/servicename/MapServer vs http //servername/arcgis/rest/services/servicename/MapServer/1).

0 Kudos
TomFlahive
New Contributor III

What about the case where you have a WebMap that has web services that may come from different sources (from different servers), so one web service might have 3 individual layers, and another web service from a different source may have 2 individual layers, and so on.  In that situation would I need an IdentifyTask for each service?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tom,

  Correct one for each service (not each service layer).

TomFlahive
New Contributor III

Got it.  Thanks Robert!

0 Kudos