-1

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.

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.

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();


  • Thanks, does that remove all of the graphics or only the selected graphics? – Mike Horn Oct 14 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.