This repository was archived by the owner on Apr 18, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -142,20 +142,18 @@ const polygonKonva = async (points, done) => {
142142 try {
143143 const delay = ( ) => new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
144144 const stage = window . Konva . stages [ 0 ] ;
145- const firstCoords = points [ 0 ] ;
146145 for ( let point of points ) {
147146 stage . fire ( "click" , { evt : { offsetX : point [ 0 ] , offsetY : point [ 1 ] } } ) ;
148147 await delay ( ) ;
149148 }
150149
150+ // this works in 50% runs for no reason; maybe some async lazy calculations
151+ // const firstPoint = stage.getIntersection({ x, y });
152+
153+ // Circles (polygon points) redraw every new click so we can find it only after last click
154+ const lastPoint = stage . find ( "Circle" ) . slice ( - 1 ) [ 0 ] ;
155+ const firstPoint = lastPoint . parent . find ( "Circle" ) [ 0 ] ;
151156 // for closing the Polygon we should place cursor over the first point
152- const [ x , y ] = firstCoords ;
153- const firstPoint = stage . getIntersection ( { x, y } ) ;
154- if ( ! firstPoint ) {
155- const getInfo = t => [ t . className , t . x ( ) , t . y ( ) ] . join ( " " ) ;
156- const allPoints = window . Konva . stages [ 0 ] . find ( "Circle" ) . map ( getInfo ) ;
157- return done ( `First point [${ x } , ${ y } ] was not found (${ allPoints } )` ) ;
158- }
159157 firstPoint . fire ( "mouseover" ) ;
160158 await delay ( ) ;
161159 // and only after that we can click on it
You can’t perform that action at this time.
0 commit comments