When using fabric js, I have successfully drawn various shapes like circles and rectangles. However, I encountered an issue while trying to obtain the coordinates of the rectangle using the fabric.rect()
method.
canvas.getActiveObject().get('points');
Unfortunately, this code snippet returned undefined
, leaving me confused about how to proceed. I even referred to a post on Stack Overflow titled How to get polygon points in Fabric.js, but it did not provide a solution to my problem.
var object = canvas.getActiveObject();
var objectCenter = object.getCenterPoint();
var translatedPoints = object.get('points');
console.log(object);
console.log(translatedPoints);
translatedPoints.map(function(p) {
var pt = {
x: objectCenter.x + p.x,
y: objectCenter.y + p.y
};
console.log(pt);
So, if anyone knows a way for me to retrieve the coordinates of active objects such as rectangles drawn using similar methods, I would greatly appreciate the assistance.