-1
I create SVG elements (circles) with Javascript code dynamically. The problem is that I want to pass these circles to a file with extension .svg. If you create the elements in html, it would just copy them to the file, passed each one’s position variables. But as they are created dynamically, how can I show them in a svg file and then open with an editing program. Example as I create:
<line title="Vertical" x1=60 y1=60 x2=60 y2=460 stroke-width=2 stroke=black />
And in the file to create is:
fwrite($hndl, "<line title='Vertical' x1='60' y1='60' x2='60' y2='460' stroke-width='2' stroke='black' /> \n");
Now with the code dynamically:
for (var i = 0; i < steps; i++) {
var x = stepX * (i + 1);
var y = stepY * (i + 1);
//create circle
var shape = document.createElementNS(
"http://www.w3.org/2000/svg", "circle");
shape.setAttributeNS(null, "cx", originX + x);
shape.setAttributeNS(null, "cy", originY - y);
shape.setAttributeNS(null, "r", 5);
shape.setAttributeNS(null, "fill", "green");
shape.setAttributeNS(null, "class", "draggable");
shape.setAttributeNS(null, "order", i);
shape.setAttributeNS(null, "id", i);
shape.id="circle"+i;
svg.appendChild(shape);
}
How can I put them in the file?
Elements are already created dynamically, like this in the code before they are passed to the file. I want to be in SVG code inside the file(svg) and then can edit with software.
– akm