@@ -139,21 +139,29 @@ const clickMultipleKonva = async (points, done) => {
139139 * @param {function } done
140140 */
141141const polygonKonva = async ( points , done ) => {
142- const delay = ( ) => new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
143- const stage = window . Konva . stages [ 0 ] ;
144- const firstCoords = points [ 0 ] ;
145- for ( let point of points ) {
146- stage . fire ( "click" , { evt : { offsetX : point [ 0 ] , offsetY : point [ 1 ] } } ) ;
142+ try {
143+ const delay = ( ) => new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
144+ const stage = window . Konva . stages [ 0 ] ;
145+ for ( let point of points ) {
146+ stage . fire ( "click" , { evt : { offsetX : point [ 0 ] , offsetY : point [ 1 ] } } ) ;
147+ await delay ( ) ;
148+ }
149+
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 ] ;
156+ // for closing the Polygon we should place cursor over the first point
157+ firstPoint . fire ( "mouseover" ) ;
147158 await delay ( ) ;
159+ // and only after that we can click on it
160+ firstPoint . fire ( "click" ) ;
161+ done ( ) ;
162+ } catch ( e ) {
163+ done ( String ( e ) ) ;
148164 }
149-
150- // for closing the Polygon we should place cursor over the first point
151- const firstPoint = stage . getIntersection ( { x : firstCoords [ 0 ] , y : firstCoords [ 1 ] } ) ;
152- firstPoint . fire ( "mouseover" ) ;
153- await delay ( ) ;
154- // and only after that we can click on it
155- firstPoint . fire ( "click" ) ;
156- done ( ) ;
157165} ;
158166
159167/**
0 commit comments