Select to view content in your preferred language

HitTest not returning results for polygons with transparent fill

261
5
a month ago
DSmith_InnovateInc
New Contributor

It looks like MapView.hitTest() is not returning any results for polygon features with fully transparent fill. This screenshot shows click locations and hitTest results filtered on layer title (filter should be fine) for two polygons in the same layer.

tp_fill.png

It looks like there was a similar issue around 4.5 with polygon fills of any transparency, but apparently the fix did not cover fully transparent polygons. If there's not something wrong with my setup, then transparent fill polygons essentially act like polylines for the purpose of hitTesting.

> Running 4.29

0 Kudos
5 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

I am not able to reproduce the behavior you describe. Here is a codepen showing hitTest returning results with no fill - https://codepen.io/U_B_U/pen/YzbPKrO?editors=100

 

0 Kudos
JoelBennett
MVP Regular Contributor

The behavior does occur if you set the style property to "none"...perhaps that's what's going on.

0 Kudos
UndralBatsukh
Esri Regular Contributor

Ah! I am able to reproduce the issue. I will update you once we fix the issue. Thank you for reporting this issue. 

UndralBatsukh
Esri Regular Contributor

Hi there, 

So I was wrong to say that it is a bug at 4.29. It turns out that if the style is none, the JS API assumes  there is no fill and so nothing is returned in the hit test unless the user clicks the outline. The correct behavior is to update your code by setting a transparent fill if you want a hit returned. 

Sorry about the confusion. 

0 Kudos
DSmith_InnovateInc
New Contributor

Thanks Undral and Joel. Okay, I can see some instances where you want to make only the outline of a polygon clickable for a hit test by giving it style: "none". It appears hitTest also doesn't provide results for CIMPolygonSymbols with only a CIMSolidStroke defined. I don't know how symbols on my webmap ended up with vector fill polygons with no fill defined, but they did.

Screenshot 2024-05-13 175613.png

A follow up question would be whether the Map Viewer UI should have the option to add fill symbology if none are initially defined. I had to restart with a new Vector polygon before I would see an option to change the fill properties.

 Template symbols as I found them in MapViewerTemplate symbols as I found them in MapViewerRestarting the template symbol --> polygon fillRestarting the template symbol --> polygon fillTemplate symbol with fill options after restarting.Template symbol with fill options after restarting.

0 Kudos