MapView hitTest() doesn't work on certain geometries from FeatureLayer

586
4
06-15-2023 01:10 PM
LucasBertoni
New Contributor II

Hi, noticed that the hitTest on MapView fails to return some geometries, even though it is very clear they should be hit.

I modified Esri sample and introduced a "problematic" geometry on this codepen, this also happens when the features are being loaded from the server:

https://codepen.io/Lucas-Bertoni-the-decoder/pen/jOQWQeV?editors=1000

Here is a video demonstrating/explaining the issue:

https://drive.google.com/file/d/1t4C_QmrEp2z8VrnpRG2rVpKiEfVY7T_o/view?usp=sharing

Has anyone else ever faced such an issue? Why does that happen and how to workaround it?

Thanks.

4 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

You getting the error because you are trying to query a feature using fields that do not exist on the layer. You must set the fields in the layer's field schema and also set the attributes on the features.  Year and name fields do not exist in the case (actually all other fields in this case). 

 query.where = "YEAR = " + year + " AND NAME = '" + name + "'";

 

You also must set the outFields on the FeatureLayer so that fields are also available on the FeatureLayerView since you are doing the query on the layer view. I updated your codepen to add the missing pieces. Please take a look at the codepen: https://codepen.io/U_B_U/pen/MWzJMRR?editors=1000

Some useful docs: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#creating... - Please read Add an array of client-side features section on how to create client-side feature layer.

FeatureLayer.outFields: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#outField...

Hope this helps,

-Undral

0 Kudos
LucasBertoni
New Contributor II

Hi, @UndralBatsukh thanks for your response.

As I mentioned in my opening statement, the issue also happens when the feature layer is being loaded from a server (where it is properly configured with all properties). I simply modified an Esri sample to reproduce the issue and provide an example.

Please double-check the video demo I provided, this issue is about the hitTest itself. Your solution is unrelated, notice that in your codepen problem still happens, where the hitTest fails to trigger when the mouse pointer is over this area:

LucasBertoni_0-1687881229454.png

Let me know if you need more details.

Thanks.

UndralBatsukh
Esri Regular Contributor

Would have been easier if your codepen did not return errors. In any case, I am able to see the behavior you describe. If you set the SimpleLineSymbol width to <=1.5 then the hittest returns results consistently at the bottom segment. We will look into this behavior and I will update you once we address it.

TimSexton1
Occasional Contributor

Could this issue be related even though it is JS API 3.x instead of 4.x?
https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/snapping-issue-with-arcgis-api-fo...

0 Kudos