如何使用 KonvaJs 插件获取多边形等形状的中心点?

How to get the center point of a shape like polygon use KonvaJs plugin?

如何使用 konva 获取多边形等形状的中心点? 我需要在形状的中心添加一些文本标签。

您可以使用 shape.getClientRect() 来获取形状的边界客户矩形。

则中心的绝对位置为:

const box = shape.getClientRect();
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;