0

I am using the sketch widget for ArcGIS JavaScript: https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html

There is a "delete" button after you have selected one or more graphics. Is there a way to trigger the delete operation through the API?

I don't see one in the documentation.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 11, 2019 at 23:47

3 Answers 3

1

There's no method on the Sketch widget to delete a particular or selected graphic.

One posible option is to do it manually using the updateGraphics property of the widget which is a Collection of the graphics that are being edited/selected in that moment.

With that information we can use the method removeMany() from the "graphics" property(Collection) of your GraphicsLayer to remove them.

...
function deleteGraphics() {
 const selectedGraphics = sketchWidget.updateGraphics; //Get selected graphics from the widget
 if (selectedGraphics) {
 graphicsLayer.graphics.removeMany(selectedGraphics); //We remove them from our layer
 }
 sketchWidget.complete(); //We "complete" the "update" event, setting updateGraphics to empty
}
...

If someone else has a better way to do it I will be happy if its posted, since I'm new to the ArcGIS JS API.

answered Nov 12, 2019 at 16:27
0

You have to remove the graphics from layer attached to the Sketch widget : https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#layer

 const graphicsLayer = sketch.layer;
 graphicsLayer.removeAll();
answered Oct 14, 2019 at 10:35
1
  • Thanks, does that remove all of the graphics or only the selected graphics? Commented Oct 14, 2019 at 15:38
0

As of version 4.14, there is now a delete method on the Sketch class.

sketch.delete();

This will delete the selected graphics associated with the Sketch instance.

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#delete

answered Apr 20, 2021 at 20:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.