Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  124] [ 3]  / answers: 1 / hits: 5122  / 5 Years ago, tue, september 3, 2019, 12:00:00

Im trying to clear the layer from every circle and line (remove it completely) but keep the image in the background.



If I use layer.clear() it removes the image also.



Question: How to clear the layer but avoid removing the image?



https://codesandbox.io/s/sharp-night-t4vtt


More From » konvajs

 Answers
5

layer.clear() do not remove objects from the scene. It is just clear canvas element and on the next layer.draw() all objects will be drawn again.



Instead of layer.clear() you need to remove objects, that you don't need anymore. From the demo, I see that you need to remove lines and circles. You can use layer.find(selector) to find that nodes and destroy them.



document.getElementById(btn).addEventListener(click, () => {
layer.find('Line').destroy();
layer.find('Circle').destroy();
layer.draw();
});

[#6363] Saturday, August 31, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tierney

Total Points: 45
Total Questions: 101
Total Answers: 94

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
;