admin管理员组文章数量:1222244
I am currently drawing a rectangle with a transformation on his parent element (g). The resulting svg is this;
<svg version="1.1" width="1055" height="381">
<g transform="rotate(120)">
<rect x="0" y="0" width="100" height="100" rx="10" ry="0" stroke-width="0" style="stroke:rgb(0,0,0)" id="rect-0"></rect>
<rect x="100" y="0" width="100" height="100" rx="10" ry="0" stroke-width="0" style="stroke:rgb(0,0,0)" id="rect-1"></rect>
</g>
</svg>
Now I am trying to retrieve the coordinates of one of the rects dynamically, but using getBBox does not return the correct result. Can anyone tell me how to get the correct x, y, width and height properties of one of the rects?
I am currently drawing a rectangle with a transformation on his parent element (g). The resulting svg is this;
<svg version="1.1" width="1055" height="381">
<g transform="rotate(120)">
<rect x="0" y="0" width="100" height="100" rx="10" ry="0" stroke-width="0" style="stroke:rgb(0,0,0)" id="rect-0"></rect>
<rect x="100" y="0" width="100" height="100" rx="10" ry="0" stroke-width="0" style="stroke:rgb(0,0,0)" id="rect-1"></rect>
</g>
</svg>
Now I am trying to retrieve the coordinates of one of the rects dynamically, but using getBBox does not return the correct result. Can anyone tell me how to get the correct x, y, width and height properties of one of the rects?
Share Improve this question edited Jul 28, 2011 at 14:44 Thizzer asked Jul 28, 2011 at 11:52 ThizzerThizzer 16.7k28 gold badges103 silver badges142 bronze badges1 Answer
Reset to default 20I found the solution myself;
var matrix = shape.getCTM();
// transform a point using the transformed matrix
var position = svg.createSVGPoint();
position.x = $(shape).attr("x");
position.y = $(shape).attr("y");
position = position.matrixTransform(matrix);
本文标签: javascriptRectangle coordinates after transformStack Overflow
版权声明:本文标题:javascript - Rectangle coordinates after transform - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739380032a2160662.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论