Select to view content in your preferred language

hitTest and Obscured Features

719
2
02-11-2022 12:00 PM
james-rae
New Contributor III

Good day.

Hunting for an answer to a scenario I'm dealing with. Using JS API v4.22.2.

I have a 2D map where the user can add layers of varying types (FeatureLayer, MapImageLayer, etc), and also control the layer order on the map. I provide a hover event (resulting in a custom maptip, or possibly something else) when the mouse cursor goes over a visible feature in a FeatureLayer. No hover magic on MapImageLayers.

The hitTest provides me the topmost feature under the mouse from all FeatureLayers, but if that feature is obscured by a symbol from a MapImageLayer higher in the layer stack, I've yet to find a way to detect that case. As is now, the obscured feature will still fire the hover event, which gives a funny user experience. They expect the mouse to be reacting with the visible symbol (in this case, no hover because MapImageLayer), not a reaction from something lurking underneath it.

This wasn't a problem in API v3, as raster layers had to be beneath the vector ones, and the SVG stack had a pretty hard link to what the mouse was over for events.

My guts say the solution is either something obvious that's eluding me, or this "raster overlaying vector" scenario is too niche for the API to support.

For the inevitable "why" question, we use MapImageLayers of features for performance reasons when the feature set is massive.

Any insights are appreciated.

0 Kudos
2 Replies
BlakeTerhune
MVP Regular Contributor
0 Kudos
james-rae
New Contributor III

Appreciate the links, learned a few new features from it. Unfortunately the server aggregation appears to be AGOL only and the rest need the vertices already on the client or a modded service.  So I'm either solving this or writing a work-around (like hoisting the hover'd symbol to a secret layer above everything to at least give context to the maptip).

Regardless, thanks again for replying.

0 Kudos