Shape position after drag

71 views
Skip to first unread message

Tony Morgan

unread,
Nov 6, 2021, 7:57:24 AM11/6/21
to Snapsvg
Hi. I'm a newcomer to Snap, so please excuse my ignorance.

I have functions that need the current position of a shape. If I access the x,y coordinates for a shape I get the location where it was originally defined, not where it is right now. How can I get the current position of a shape that might have been dragged?

Ian

unread,
Nov 6, 2021, 8:12:42 AM11/6/21
to Snapsvg
If its been dragged you probably need to look at the transform and it's matrix. I think matrix.split() will provide dx and dy which is it's translation. 

So something like     someElement.transform().localMatrix.split().dx   &    someElement.transform().localMatrix.split().dy

This supposes that the drag is simple, no rotations, scales etc.

Ian

Ian

unread,
Nov 6, 2021, 8:13:49 AM11/6/21
to Snapsvg

Just to add, if you are doing the drag code yourself, you may find it easier to just store whatever drag you are doing in a variable! I'm assuming you can't do that with my previous response.

Tony Morgan

unread,
Nov 7, 2021, 7:37:17 AM11/7/21
to Snapsvg
A found a simple solution, which is to use getBBox on the moved shape and work from the BBox coordinates.
Reply all
Reply to author
Forward
0 new messages