SVG getScreenCTM(), , SVG .
. , SVGMatrix inverse(), .
, , clientX clientY . SVG .
<html>
<object data="324196.svg"
type="image/svg+xml"
id="canvas"
style="width:400px;height:400px;border:1px solid black;" onclick="calc()"></object>
</body>
<script>
canvas.addEventListener("load",function(){
document.getElementById("canvas").contentDocument.addEventListener("click", calc);
});
function calc(evt)
{
var svg = document.getElementById("canvas").contentDocument.firstChild;
var point = svg.createSVGPoint();
point.x = evt.clientX;
point.y = evt.clientY;
point = point.matrixTransform(svg.getScreenCTM().inverse());
var circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circle.setAttribute("cx", point.x);
circle.setAttribute("cy", point.y);
circle.setAttribute("r", "5");
circle.setAttribute("fill", "red");
circle.setAttribute("fill-opacity", "0.5");
svg.appendChild(circle);
}
</script>
</html>
source
share