identify task only identifying items from a single layer

1396
2
Jump to solution
05-31-2019 10:56 AM
EllaHaines
New Contributor III

I am trying to use identify task with layerOption "all" ("visible" would be better but IIRC that has never worked and I don't have time to deal with that right now) to return items from all the layers in a map service when the user clicks the map. If multiple points from one layer are overlapping, it returns those, but if there are overlapping items from multiple layers in the MapImageService it only returns a response with items from that one layer.

I think dynamic layers are enabled in the map service, but I am not using that functionality in my script.

var fieldDataImageLayer = new MapImageLayer({
            url: "https://myRESTurl/MapServer/",
            title: "Field Data"
        }); ‍‍‍‍
        function executeIdentifyTask(event) {
            //set up identify task for different layer types.
            tasks = [];
            fieldDataIdentifyTask = new IdentifyTask({
                url: fieldDataImageLayer.url,
                layerOption: "all",
                //layerIds: [0,1,2,3,4,5,6,7,8,9,] - this didn't help
            });

            tasks.push(fieldDataIdentifyTask);

            //common parameters
            params = new IdentifyParameters();
            params.tolerance = 12;
            params.returnGeometry = true;
            params.width = view.width;
            params.height = view.height;
            //allow picking top layer only (default behavior)
            params.geometry = event.mapPoint;
            params.mapExtent = view.extent;
            //process and resolve multiple promises at once
            var promises = [];
            for (i = 0; i < tasks.length; i++) {
                promises.push(tasks[i].execute(params));
            }

            var responses = new all(promises);
            return responses;
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

the promises thing initially made more sense when I was targeting multiple map image services

Do I just need to convert everything to 10 different feature layers and just use HitTest() at this point? Would that mess up the layerlist groupings and map render speed? There are thousands of points.

ETA: It looks like when I specify the "layerIds: [5]" or whatever single sublayer, and click on an item from another sublayer, it still returns results even thought that layerId isn't in the array. 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You don't appear to be constructing that correctly. There's no layerIds or layerOption property in IdentifyTask, but they are in IdentifyParameters.

Take a look at the IdentifyTask sample: ArcGIS API for JavaScript Sandbox 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

You don't appear to be constructing that correctly. There's no layerIds or layerOption property in IdentifyTask, but they are in IdentifyParameters.

Take a look at the IdentifyTask sample: ArcGIS API for JavaScript Sandbox 

EllaHaines
New Contributor III

Thanks, that did the trick. It must have been defaulting to "top," although somehow I was expecting that to return only the topmost feature instead of all the overlapping features in that sublayer.

Looks like the "visible" option still isn't fixed though (I think in the past I had to get the visible layers and put that into the layerIds array).

0 Kudos