Hello!
I seem to be having issues selecting Features when drawing a Graphic? I have a button click that adds a rectangle GraphicsLayer from the SketchViewModel, but not sure how to get the Geometry of the rectangle to select or query the Features that intersect?
The online examples seem overly complex just for a Geometry intersection?
here is the graphics section that works-
You'll need to grab the geometry from the graphic that exists on the graphics layer (tempGraphics) and then you can use that geometry to do your intersect query against a set of features.
This sample illustrates it relatively well:
https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=sketch-update-validation
In this sample they do it on update of sketch - but you can tie it into whatever fits your situation.
The relevant part is:
const graphic = event.graphics[0];
// check if the graphic is intersecting school buffers or is
// still contained by the boundary polygon as the graphic is being updated
intersects = geometryEngine.intersects(buffers, graphic.geometry);
contains = geometryEngine.contains(boundaryPolygon, graphic.geometry);
If you want to intersect against a featureLayer you can instead use the graphic.geometry and then do a layer query supplying that geometry as a parameter.
https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=featurelayer-query-basic
Please take a look at this sample: https://developers.arcgis.com/javascript/latest/sample-code/highlight-features-by-geometry/
Note that that sample isn't working correctly. Draw a rectangle to select features.
Clear the selection and draw another rectangle. Both the features in the current rectangle and the previously selected features are highlighted.
Hi there,
Oh!!! Thank you for reporting the issue!
highlightIds and features variables are set as arrays at the top of the app so they keep getting features added to them. It needs to be instantiated in the callback so it's clean. I updated the sample and here is a codepen that works - https://codepen.io/U_B_U/pen/poXdBMx?editors=100
The sample should be updated on the SDK page next week.
What's happening with the Total and Selection counts if you select multiple rectangles without clearing the selection? I've selected just single parks with two rectangles, but the selection says 3.
codepen updated