我想在Fabric.js中绘制一个带有鼠标交互的fabric.Polygon。我做了一个小的jsfiddle来显示我的实际状态:http://jsfiddle.net/Kienz/ujefxh7w/
按ESC键后,将取消“交互式绘制模式”,并最终确定多边形。但是现在多边形的位置是错误的(控件是正确的)。
有谁有主意吗?
发布于 2020-03-03 17:46:24
对于那些正在寻找使用fabricjs 3的更新答案的人。
FabricJS有很多更改,其中之一是对_calcDimmensions方法的更改。它不再在对象上存储值minX和minY。相反,它会返回一个包含以下内容的对象:
{
left: minX,
top: minY,
width: width,
height: height
}因此,考虑到这一点,解决方案更新为以下内容:
currentShape.set({
points: points
});
var calcDim = currentShape._calcDimensions();
currentShape.width = calcDim.width;
currentShape.height = calcDim.height;
currentShape.set({
left: calcDim.left,
top: calcdim.top,
pathOffset: {
x: calcDim.left + currentShape.width / 2,
y: calcDim.top + currentShape.height / 2
}
});
currentShape.setCoords();
canvas.renderAll();https://stackoverflow.com/questions/26219238
复制相似问题