主要代碼
/** transform matrix start */
// rect: svg 圖形元素;self.g: 當(dāng)前進(jìn)行 transform 的元素,即 需要計算 transform 后坐標(biāo)的點所在的進(jìn)行 transform 的容器
// getPointAtLength: SVG路徑對象.getPointAtLength(len), 該方法返回路徑上指定距離的點的坐標(biāo),此處為 rect 左上角的點的坐標(biāo)
const localPoint = rect.node().getPointAtLength(0)
const localTransformList = self.g.node().transform.baseVal
let localMatrix = self.g.node().viewportElement.createSVGMatrix()
// is there at least one entry?
if (localTransformList.length) {
// consolidate multiple entries into one
localMatrix = localTransformList.consolidate().matrix
}
const transformedPoint = localPoint.matrixTransform(localMatrix)
/** transform matrix end */