• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Get X and Y of a shape inside a group after dragging in Konva JS

Resolved: Get X and Y of a shape inside a group after dragging in Konva JS

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I want to be able to drag and drop a group of objects (rect, text, circle, etc.) and get their new x,y position in order to keep them in that new position.
I’ve checked the documentation for Konva.jS for dragging a group, but with no luck.
What I did try is I can get the new relative x,y position for the group (group.attrs.x, group.attrs.y) but it is not exactly the same as the real position of any of the object inside the group. I’ve tried to tweak it by incrementing x,y but still it is different for different size of objects (in case of text with different length).
enter image description here
In the above image, +22 was added to the new x and y respectively that I got from the group using group.attrs.x, group.attrs.y, but the resulting circle (dot) is different for two different objects (rect or text).
I need to get (near) exact x,y position of the circle in this case. How can I do it?
I have included here a simple demo for dragging a group of objects, at the drop it is drawing a circle from the group‘s new x,y positions. And there you can see the difference.


Answer:

First thing that stands out is you are using mouseout as the dropped according to the documentation there is a dragend, I think that is what we should be using on this case:
https://konvajs.org/docs/events/Binding_Events.html
To get the position you are looking for you need to add the group and your rectangle, take a look at the example below, it should all make sense, let me know if you have any questions.


If you have better answer, please add a comment about this, thank you!

html5-canvas javascript konvajs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Java Swing center JLabel in JPanel with two JLabels

27/03/2023

Resolved: How to compare two text files and and change the sign of the data in powershell?

27/03/2023

Resolved: Java Virtual Machines deleted

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.