I want to let users rotate objects on the Fabric.js powered canvas, but limit their rotation to 90 deg increments. Idea is that as they rotate and then stop, the object woul
Run setCoords() after setAngle(). This will update the position of the controls. Tried it in your fiddle. Works fine.
canvas.on("object:modified", function(modEvtData) {
// modified fires after object has been rotated
var modifiedObj = modEvtData.target;
if (modifiedObj.angle && snapAfterRotate) {
modifiedObj.setAngle(lastClosestAngle).setCoords();
snapAfterRotate = false;
canvas.renderAll();
}
})
regards, Benick
FabricJS now supports this natively through 'setAngle', along with 'snapThreshold' property.
https://github.com/kangax/fabric.js/pull/3383
Example:
canvas.add(new fabric.Circle({
snapAngle: 90,
snapThreshold: 45,
left: 100,
top: 100,
radius:50,
fill: '#9f9',
centeredRotation: true
}));
https://jsfiddle.net/2t2d1zj9/1/