Get Graphic(s) at Click Location?

457
7
05-15-2019 04:43 AM
TonyCollins
New Contributor III

Hi

If I have a GraphicsLayer with say 3 graphics added to it that overlap is there a way from a click on the overlap area to return all three graphics?

I started with view.hitTest(), but this only returns the topmost graphic, not all graphics under the click.


I then looked at layerView.queryFeatures() but the promise never occurs so I wonder if this does work with a Graphics Layer?

So basically, using v4 is there a way to get all graphics from a single Graphics Layer that intersect a point (cliick).

Many Thanks,

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Tony,

   A GraphicsLayer has a GraphicsLayerView and a queryGraphics method (not QueryFeatures).

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-GraphicsLayerView.ht...

0 Kudos
TonyCollins
New Contributor III

Hi Robert 

I did see that, but there are no parameters to pass in a query/geometry; so it looks like all that does is return all graphics from a Graphics Layer rather than a subset?

Thanks,
Tony

0 Kudos
TonyCollins
New Contributor III

... the only thing I could think of was using contains/intersects from the geometryEngine)against each graphic.geom, but it seems a but OTT.oes not offer the

I find it a little odd that hitTest only offers the top most

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tony,

  Now I remember. The recommendation from the team is to use a FeatureLayer from a graphics collection instead.

0 Kudos
TonyCollins
New Contributor III

Hi Robert, 

Not sure what you mean. Create a FeatureLayer from a graphics collection to then query?

Thanks,

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tony,

  Yes instead of using a GraphicsLayer, use a FeatureLayer and then you can use queryFeatures.

0 Kudos
TonyCollins
New Contributor III

Oh wow, OK,

I am using the SketchViewModel for the drawing/transformation part of the application. Seems like this is going to be a real pain to to flip back and forward from the GraphicsLayer to FeatureLayer just to allow selection of overlapping graphics.

0 Kudos