Hello everyone,
I am working with the ArcGIS API for JavaScript 4.34 in a React + Vite project (TypeScript).
I would like to know whether it is possible to select existing graphics (for example, points stored in a GraphicsLayer) using the selection tools of the Sketch widget (rectangle / lasso), and if so, what the recommended approach is.
Technical context
- Environment: React + Vite
- API: ArcGIS JS API 4.34
- ES module imports, for example:
import Sketch from "@arcgis/core/widgets/Sketch.js";
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer.js";
- I do not use @ArcGIS/map-components, as my application contains several custom widgets and an existing React architecture.
- The Sketch widget is attached to a dedicated GraphicsLayer used only for drawing.
- The graphics to be selected (points, polygons, etc.) are stored in another existing GraphicsLayer already added to the map.
Goal
- Use the selection tools of the Sketch widget (rectangle / lasso)
- To select existing graphics
- And retrieve the selected features (IDs or graphics) in order to update React state
What I have observed
The "create" and "update" events work correctly to retrieve the drawn geometry.
The documentation indicates that "selection-change" can be accessed via event.toolEventInfo within the "update" event, but:
I am not sure whether:
The Sketch widget can directly handle the selection of external graphics
Or if the intended approach is to use the drawn geometry to perform a manual spatial selection (e.g. geometryEngine.intersects, etc.)
Questions
Is it officially supported to use the Sketch widget’s selection tools to select existing graphics?
If yes, what is the recommended approach (event, property, or workflow)?
If not, what is the best practice with the 4.x API to implement this kind of selection while keeping the Sketch widget UX?
Thank you in advance for your help and any examples you may be able to share.
Best regards,
Karim