简体   繁体   English

如何使用svg.js向已创建的多边形添加点

[英]How to add points to already created polygon using svg.js

I've written some code which determines when user clicks on a polygon near to edges. 我编写了一些代码,该代码确定用户何时单击靠近边缘的多边形。 I collect the mouse coordinates and want to add this point to polygon. 我收集了鼠标坐标,并希望将此点添加到多边形。 For this, I'm adding points to poly.array().value on proper location. 为此,我在适当的位置将点添加到poly.array().value But I'm not able to understand how should it be reflected on the screen. 但是我不明白如何在屏幕上反映出来。

Sample code 样例代码

poly.on('mousedown', function(event){
    var points = myCanvas.point(event.x, event.y);
    var polyArray = poly.array().value;
    polyArray.splice(i+1, 0, [points] );
});

Possible approach that I can think (seems a hack not the proper solution) is to add points to polygon SVG element manually. 我认为可能的方法(似乎是一种错误的解决方案)不是手动将点添加到多边形SVG元素。 I was wondering if there is a method in svg.js element to update the element and replot it. 我想知道svg.js元素中是否有一种方法来更新该元素并重新绘制它。

我检查了svg.draw.js的源代码,发现有一个方法可以用新点poly.plot(polyArray);重新绘制多边形poly.plot(polyArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM