How do I disable Sketch widget from onCreate complete

170
1
12-04-2023 11:25 AM
ViktorSafar
Occasional Contributor II

I would like to disable the Sketch widget in the onCreate handle for state "complete".

 

If I do it via .destroy(); inside the handler, I get the following error

 

SketchViewModel.js:5 Uncaught (in promise) s {name: 'AbortError', details: undefined, message: 'Aborted'}

 

 

The only way I found to work is to fire the .destroy() after a timeout. Is there a better way?

 

 

const handleOnCreate = (event) => {
	if (event.state === 'complete') {
	  // my processing 

	  //setTimeout(() => {
	  currentSketch?.destroy();
	  //}, 200);
	}
};


const sketchGraphicsLayer = mapView.map.findLayerById(layerName);
const sketch = new Sketch({
  layer: sketchGraphicsLayer,
  view: mapView,
});

sketch.on('create', function (event) {
  handleOnCreate(event);
});

 

 

 

0 Kudos
1 Reply
MatthewDriscoll
MVP Alum

Creation Mode is continuous by default.  Use single.

const sketch = new Sketch({
  layer: sketchGraphicsLayer,
  view: mapView,
  creatioMode: "single"
})
0 Kudos