SketchViewModel doesn't update graphic programatically

329
0
12-20-2021 11:43 AM
ironmaskito
New Contributor III

I am able to update the vertices of my Sketch graphic using the cursor, but am unable to do so programatically. Below you can see that when I change the location of a vertices of the drawn Graphic, the vertex changes, but the lines don't get redrawn to the new vertex location. Here is some sample code showing my attempt to modify the path of the graphic. Any help is much appreciated. I am using ArcGIS js version 4.21

I have noticed the difference when I am editing coords programatically is that the update complete listener with state === 'complete' and aborted === true, whereas when manually moving coords state === 'active' and aborted === false

UPDATE: I got it to work, using below code, but I don't think this is the recommended way of doing it. since graphic may not be found in sketch view model Would still appreciate alternative solutions.

 

   const graphic: Graphic = getSketchGraphic();
   const polylineDrawing: Polyline = graphic.geometry as Polyline;
   polylineDrawing.paths[0][0] = [newCoordX, newCoordY];
   const graphicClone: Graphic = graphic.clone();
   SketchVM.getLayer().removeAll();
   SketchVM.getLayer().add(graphicClone);
   SketchVM.update(graphicClone, updateOptions);

 

 

 

ORIGINAL ATTEMPT

 

 

 

      const graphic: Graphic = getSketchGraphic();
      const polylineDrawing: Polyline = graphic.geometry as Polyline;
      polylineDrawing.paths[0][0] = [newCoordX, newCoordY];
      SketchVM.update(graphic, {tool: 'reshape'});

 

 

 

 

 

 

 

sketch update prob.png

0 Kudos
0 Replies