svgdotjs / svg.draw.js

An extension of svg.js which allows to draw elements with mouse
MIT License
239 stars 57 forks source link

How can we draw on existing SVG? #25

Open dani2819 opened 7 years ago

dani2819 commented 7 years ago

I draw a line on svg, now i have a button, on its click function i put a following logic: var draw = SVG(document.getElementById('drawing')).size('100%', '100%'); var polyline = draw.polyline(); polyline.fill('none').stroke({ 'color':'red', 'linecap':'round' }).draw();

The same logic is in window onload function, which executed successfully and we can draw a polyline. But when i clicked on button i want to re-initialize this i can draw another polyline on this svg but i cant.

Fuzzyma commented 7 years ago

I see no issue with the code. It should work this way

dani2819 commented 7 years ago

<script type="text/javascript"> var polyline; var draw; window.onload = function() { var element = document.getElementById('drawing'); draw = SVG(element).size('100%', '100%'); polyline = draw.polyline(); polyline.fill('none').stroke({ 'color':'red', 'linecap':'round' }).draw(); element.addEventListener('mousedown', function(event){ //if right click then fire done event if(event.which==3){ polyline.draw('done');} }); }; //end window.load function drawagain(){ draw = SVG(document.getElementById('drawing')).size('100%', '100%'); polyline = draw.polyline(); polyline.fill('none').stroke({ 'color':'red', 'linecap':'round' }).draw(); } </script>

dani2819 commented 7 years ago

The above one is the whole code, When you click on button then function drawagain() executed.