您需要用.getPointAtLength(i)
方法遍历路径长度,然后找到限制。似乎是一个有趣的事情,所以我做了一个快速和肮脏的实施,这是重要的部分:
function findLimits(path) {
var boundingPoints = {
minX: {x: dimensions.width, y: dimensions.height},
minY: {x: dimensions.width, y: dimensions.height},
maxX: {x: 0, y: 0},
maxY: {x: 0, y: 0}
}
var l = path.getTotalLength();
for (var p = 0; p < l; p++) {
var coords = path.getPointAtLength(p);
if (coords.x < boundingPoints.minX.x) boundingPoints.minX = coords;
if (coords.y < boundingPoints.minY.y) boundingPoints.minY = coords;
if (coords.x > boundingPoints.maxX.x) boundingPoints.maxX = coords;
if (coords.y > boundingPoints.maxY.y) boundingPoints.maxY = coords;
}
return boundingPoints
}
您可以在这里找到实现:https://jsfiddle.net/4gus3hks/1/
什么做的完整代码你的意思是'getBBpox(0'返回一个“单点”?'getBBox()'返回路径的边界框,最左边的点应该是'bbox.x',最右边的点应该是'bbox.x + bbox.width '那是你想要的吗? –
'getBBox'可以让我知道目标点的x坐标,而不是'y'。这就是我说的只说单一坐标时的意思。 –