如何获得像多边形这样的形状的中心点使用KonvaJs插件?

问题描述 投票:0回答:1

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

konvajs
1个回答
0
投票

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

那么中心的绝对位置将是:

const box = shape.getClientRect();
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
© www.soinside.com 2019 - 2024. All rights reserved.