DragBoundFunc position incorrect on transformed stage
See original GitHub issueI implemented emulated screen scrolling of the canvas, using method 4 here: https://konvajs.org/docs/sandbox/Canvas_Scrolling.html#How-to-display-and-scroll-a-very-big-html5-canvas
Esentially the stage is re-positioned when we scroll like this:
const PADDING = 500;
function repositionStage() {
var dx = scrollContainer.current.scrollLeft - padding;
var dy = scrollContainer.current.scrollTop - padding;
stage.current.container().style.transform = 'translate(' + dx + 'px, ' + dy + 'px)';
stage.current.x(-dx);
stage.current.y(-dy);
}
Then I have a draggable rectangle with a dragBoundFunc like this:
<Rect
height={32}
width={120}
fill={'red'}
cornerRadius={8}
draggable
dragBoundFunc((pos) => {
console.log('position rectangle: ', pos)
}
/>
When the stage is initial (top: 0 , left: 0) the dragboundfunc returns the correct position. But as soon as I scroll the stage a bit , the position provided by the dragboundfunc is incorrect…
With the normal scrolling (not emulated) the dragBoundFunc position is always correct (even when the stage is scrolled)
Issue Analytics
- State:
- Created a year ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
konvajs/konva - Gitter
So newPos in dragBoundFunc must be “absolute position" of the node. Absolute position is not its top-left point.
Read more >HTML5 Canvas Complex Drag and Drop Bounds - Konva
When I zoom in/out by setting the scale of the stage, like shown in another demo here, the snapping occurs at the wrong...
Read more >React Konva Transformer Error "Cannot read property ...
There is an Masking component which imports Konva's Stage , Layout and Image and as well as the MaskingRectangle which can be transformed....
Read more >konva - UNPKG
87, - Fix wrong `mouseleave` trigger for `Konva.Stage` ... It will fire BEFORE actual position of a node is changed. 554. 555, ##...
Read more >JavaScript error with Ruby 3.1 and latest commit - Jumpstart Pro
indexOf(Xt(r))<0;){var o=me(r);if(o.transform!== ... You must return new absolute position from dragBoundFunc.")}(!this._lastPos||this.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just use
dragmove
event. Work with relative coordinates. They are much simpler to understand.Ok that works great! Makes sense - I will start using onDragMove instead.
Thanks so much for everything @lavrton - you we’re super helpful!