Problems with IdentifyTask

1242
4
Jump to solution
09-27-2018 01:15 PM
StanLambert
New Contributor II

I've already spent an entire day trying to figure this out and I've gotten nowhere.  I've implemented functionality that allows the user to draw a polygon and identify features within that polygon.  I'm using SketchViewModel for the polygon and listening to the "create-complete" event to get the geometry and execute the IdentifyTask.  

The problem is that the IdentifyTask returns ALL features within the polygon, not just the ones I specify in the layerIds property.  That includes features from hidden layers, even though I have specified to only return visible features.  Here is the relevant part of my code.

const identifyTask = new IdentifyTask(mapServiceUrl);

let params = new IdentifyParameters();
params.tolerance = 3;
params.layerIds = layerIds;
params.layerOption = "visible";
params.width = view.width;
params.height = view.height;
params.returnGeometry = true;
params.geometry = event.geometry;
params.mapExtent = view.extent;

identifyTask.execute(params).then(function (response) {
    const results = response.results;
   // process the results....
}

So assume that my layerIds value is [40].  The IdentifyTask returns features from ALL sublayers of the map service identified by
mapServiceUrl.  In this case the map service has sublayers with id's 39,40,41,42 and 43. The results of the IdentifyTask contain
features from ALL of those layers. What's more, each result coming back from IdentifyTask is assigned layer id 40 and the layer
name of the layer with id 40. Further experimentation showed that if I specify more than one layer id in my layerIds property,

such as [39,40] the IdentifyTask still returns features from all five sublayers and assigns each one a layer id of 39 and a layer name
matching the name of layer 39. So the first layer id and layer name gets assigned to all of the results coming back, regardless of which
layer the feature came from.

I'm obviously doing something drastically wrong here but I just don't see it. I've followed the documentation and played with the
sandbox example, but the one example is so different from what I'm trying to do I can't simulate this same situation.

The only other information I can think of to provide is that I'm using version 4.8 of the JavaScript API and version 10.2 of ArcGIS server.
Also, I'm rendering my map services as MapImageLayer components if that is relevant.

Hopefully someone can point me in the right direction.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

This might be a server 10.2 issue then as I tested this using 10.6.1 server and no issue at all. You should try testing a a newer server maybe one of esri's sample servers and see the difference.

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Stan,

  Strange I don't see that issue. Here is a snippet of my code:

      view.when(function() {
        // executeIdentifyTask() is called each time the view is clicked
        view.on("click", executeIdentifyTask);

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

        // Set the parameters for the Identify
        params = new IdentifyParameters();
        params.tolerance = 3;
        params.layerIds = [67, 68, 79];
        params.layerOption = "visible";
        params.width = view.width;
        params.height = view.height;
      });

      // Executes each time the view is clicked
      function executeIdentifyTask(event) {
        // Set the geometry to the location of the view click
        params.geometry = event.mapPoint;
        params.mapExtent = view.extent;

        identifyTask.execute(params).then(function(response) {

          var results = response.results;
          console.info(results);
...
0 Kudos
StanLambert
New Contributor II

Here are a couple of screenshots that illustrate the problem.  Using the Chrome developer console I printed out the parameters being passed with the identify request:

Now, here's a screenshot of the results returned from the server:

Notice how every result has the same layerId and layerName value.  Only one of the results, the second one in the list, actually came from layer 43.  The rest came from layers 40 and 41.  Layer 40 is the only visible layer in the map. However, I have tried only sending the visible layerId, 40, in the request and the results are the same. It is basically returning features from all sublayers of the map service url I am supplying to IdentifyTask, regardless of what I pass in the layerIds array.

Perhaps it has something to do with passing the geometry from the polygon.  I'll keep banging my head on the desk until I figure it out.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

This might be a server 10.2 issue then as I tested this using 10.6.1 server and no issue at all. You should try testing a a newer server maybe one of esri's sample servers and see the difference.

0 Kudos
StanLambert
New Contributor II

Yes, I pulled in a sample map service from ESRI into my application and it does seem to work differently. With the ESRI sample it correctly identifies only features from the layers I specify in the layerIds property of IdentifyParameters. The "visible" option for layerOption still does not work.  It still identifies features that are not visible on the map if I include that feature's layer id in the layerIds property of IdentifyParameters.  However, I've seen enough to know that I need to wait until we upgrade to 10.6 before I spend any more time with this.  Hopefully we will be able to do that at the first of next year.  I will re-visit the issue then.  Thanks for the suggestion!

0 Kudos