admin管理员组文章数量:1416050
Im trying to clear the layer from every circle and line (remove it pletely) 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?
Im trying to clear the layer from every circle and line (remove it pletely) 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
Share Improve this question asked Sep 3, 2019 at 10:18 PatrickkxPatrickkx 1,8809 gold badges38 silver badges66 bronze badges1 Answer
Reset to default 4layer.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();
});
本文标签: javascriptKonvaclear layer but keep the backgroundStack Overflow
版权声明:本文标题:javascript - Konva - clear layer but keep the background - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745246558a2649581.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论