Search code examples
canvaskonvajskonva

KonvaJS / Dynamically enable/disable interaction with layer


Is there an easy way in konvajs to disable the interaction/events (drag&drop/pointermove/click) for a layer and its children?

I have a setup containing multiple layers and interaction should only be possible with one layer at a time because elements from different layers are overlapping, which makes it hard for the user to click/drag the right element.

Worst would be to unregister/register every handler or intercepting all handlers, only executing the body based on the global state. As konvajs layers are individual canvas elements, I hope that there is a better way to do so (either in konvajs directly or manually on the canvas)


Solution

  • Just set layer.listening(false). It should disable all events from layer and its children.