Skip to content

Clear All Images #108

Closed Answered by personalizedrefrigerator
awmasakityan asked this question in Q&A

You must be logged in to vote

With the current API, everything in the foreground layer can be cleared with the Erase command:

// 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, .getAllComponents can be slow for large images. See the getAllComponents and Erase documentation for details.

Edit: To remove all ImageComponents (and keep everything else),

const allImages = ed…

Replies: 2 comments

You must be logged in to vote
0 replies
Answer selected by awmasakityan

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants