Clear All Images #108
-
How do I remove all images from the canvas? |
Beta Was this translation helpful? Give feedback.
Answered by
personalizedrefrigerator
Feb 13, 2025
Replies: 2 comments
-
With the current API, everything in the foreground layer can be cleared with the // Remove everything from the canvas in an undoable way
editor.dispatch(new Erase(editor.image.getAllComponents()));
// Remove everything in a way that can't be undone
new Erase(editor.image.getAllComponents()).apply(editor);
// NOTE: In older versions of js-draw, getAllComponents may be named "getAllElements".
// (In newer versions of js-draw, getAllElements is an alias for getAllComponents). However, Edit: To remove all ImageComponents (and keep everything else), const allImages = editor.image.getAllComponents().filter(c => c instanceof ImageComponent);
editor.dispatch(new Erase(allImages)); // Applies the command in an undoable way |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
awmasakityan
-
Thank you very much! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the current API, everything in the foreground layer can be cleared with the
Erase
command:However,
.getAllComponents
can be slow for large images. See the getAllComponents and Erase documentation for details.Edit: To remove all ImageComponents (and keep everything else),