More than one clicked feature per layer in SceneView - hit test or other approach

10-29-2020 07:01 AM
New Contributor


I was trying to use hitTest method of MapView and SceneView to get all clicked features from all layers displayed on view. Next we want to present user list of possibly clicked features, allow him to choose one of them and perform some action.

However, it seems that hit test returns maximally one feature per layer. As I understand API docs it's intentional, but it doesn't satisfy our requirements.

I have also tried to call hitTest method in a loop, adding already returned graphics to exclude option.

It seems that when one graphic is passed to exclude parameter then whole layer containing it is excluded from hit test.

I find this counter-intuitive and consider this behavior a bug.
Here's the TypeScript code that I wrote to try this approach to the problem:

const graphicsToExclude: __esri.Graphic[] = [];
const hitTestGraphicsDictByLayerId = new Dictionary<string, __esri.Graphic[]>();
while (true) {
const hitTestResult = await this.view.hitTest(e.screenPoint, { exclude: graphicsToExclude });
if (hitTestResult.results.length === 0)

for (const res of hitTestResult.results) {
const layerId =;
if (hitTestGraphicsDictByLayerId.containsKey(layerId)) {
const vals = hitTestGraphicsDictByLayerId.getValue(layerId);
hitTestGraphicsDictByLayerId.setValue(layerId, vals);
else {
hitTestGraphicsDictByLayerId.setValue(layerId, [res.graphic]);

const graphics = => res.graphic);
for (const g of graphics)

As a workaround for two-dimensional MapView we don't use hitTest, but instead we query all layer views using queryFeatures method for clicked features. This approach doesn't work well for three-dimensional SceneView.

Is this exclude parameter behavior intentional or a bug?

Are there any plans to extend hitTest method to return more than one graphic per layer? Possibly with new parameter controlling this behavior.

Or is there any other way to approach this problem, especially for SceneView?

Tags (3)
0 Kudos
1 Reply
Esri Contributor


what symbols do the graphics have? In 3D we return all the features that were clicked, except if the symbol is a billboarded icon (so IconSymbol3DLayer that is not on the ground). The results property should give you an array of graphics that are intersected by the mouse. We have a sample that shows this behavior:


I will update the documentation to show the limitation when using icons. Unfortunately there is no workaround if this is the case you are running into.


0 Kudos