简体   繁体   中英

KonvaJs: Change points of line when dragged

I am using KonvaJs in my project. I am creating a polygon using Konva.Line by setting closed:true . I need to figure out that whether a point is inside the polygon or not. I am using Ray-Casting algorithm to find point in polygon and it's working fine. But the problem arises when polygon is dragged. When it is dragged the vertices(points) still remains the same and because of that I am not able to get the new coordinates. How can I change the points of polygon so that I can use them? Here's the plunkr .

While dragging Konva will change {x,y} properties of Node (Circle, Rect, Line, etc). All you need is to add x and y to points :

vs.push({
  x: points[i] + poly.x(),
  y: points[i + 1] + poly.y()
});

http://plnkr.co/edit/P6xTokR4bR8o1D180k40?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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