问题
We're new to Fabric.js. We're using it to draw polygons on our canvas in overlay on a real scene. We need to move, to rotate and resize the polygon and then get back the veterxes coordinates.
After the transformation we used the API.
var originalPolyPoints = pol.get('points').map(function (p)
{
return {x: p.x , y: p.y };
});
This way, the coordinates are always the original but not the changed ones. How can we get the new coordinates?
Tried to get the transformMatrix of the polygon, but it was null. Even if we have the matrix, how can we apply it?
回答1:
I think maybe you need to call setCoords
on the objects after you modify them. This is a purposeful abstraction leak for performance reasons, according to the documentation.
回答2:
The point is that all polygon's points have absolute coordinates to the canvas. In order to get actual points coordinates, you have to perform some transformation. It's required because there could be some movements and/or transformations applied to the polygon.
Check out the following answer: https://stackoverflow.com/a/53710375/4681279
来源:https://stackoverflow.com/questions/37722343/fabricjs-and-polygon-transformed-coordinates