问题
I would like to get the new point coordinates after object being modified but when i get the points coordinates after being modified they are the same point coordinates with which I have drawn the polygon. Can anyone please tell me why it so? Below is my code,
<!--fabricjs -->
canvas.on('object:modified', function(e){
var obj=e.target;
console.log("new point coordinates "+obj.points);
});
回答1:
Below is the code I used to get the updated points with ROTATE being disabled. But if I get the updated points using below code with rotate option being enabled and after rotating the object, I get wrong set of points , so for now I have disabled the rotate option. It will be great help if any one could say how can I modify below code to have the rotate option enabled and get right set of points.
<!-- fabric js -->
canvas.on('object:modified', function(e) {
var newCoordinates = "";
var matrix = [];
var polygon = canvas.getItemById(e.target.id);
matrix = polygon.calcTransformMatrix();
var translatedPoints = polygon.get('points').map(function(p) {
return {
x: p.x - polygon.pathOffset.x,
y: p.y - polygon.pathOffset.y
};
});
for (var i = 0; i < translatedPoints.length; i++) {
translatedPoints[i].x = matrix[0] * translatedPoints[i].x + matrix[2] * translatedPoints[i].y + matrix[4];
translatedPoints[i].y = matrix[1] * translatedPoints[i].x + matrix[3] * translatedPoints[i].y + matrix[5];
}
var newUpdatedPoints = JSON.stringify(translatedPoints);
});
来源:https://stackoverflow.com/questions/38567332/how-do-i-get-point-coordinates-after-object-modified