Damdam
Damdam

Reputation: 21

Fabric js : No group member update while moving

My first question here, after years of finding solutions in other's topics ! First, sorry if my english is not perfect !

I'm using Fabric js in my application and I have to implement a button to group texts or images.

However, I noticed that, when I move the group on the canvas, the group coords are updated but not the group's objects'.

On the canvas, objects are moving well with their group, but in the console, it seems that they always have the same 'top' and 'left' values.

Is it a normal groups behaviour, in which case, I really don't understand, or there is something I am missing ?

It can be noted that I added objects in the group with the addWithUpdate(obj) method.

I really hope someone can help me !

Upvotes: 2

Views: 1404

Answers (1)

AndreaBogazzi
AndreaBogazzi

Reputation: 14731

Yes this is normal. However you can find the position without destroying and rebuilding the group in this way:

given a group that is a fabric.Group and a childObject that is a subclass of fabric.Object you can:

1) create a point with childObject top and left

var point = new fabric.Point(childObject.left, childObject.top);

2) get the group transformMatrix:

var transform = group.calcTransformMatrix();

3) transform the point with this matrix:

var actualCoordinates = fabric.util.transformPoint(point, transform);

and you should be set.

Upvotes: 3

Related Questions