How to restrict the Sketch widget

165
1
04-25-2024 08:55 AM
SaiPeketi
New Contributor III

Hi,

 

I want to restrict the sketch from sketch widget with the polygon boundary. I'm aware that we can get the geometry with event of click

sketch.on("create, (event) => {

if(!(geometryEngine.within(event.graphic.geometry, polygon))) {

return;

}

});

but I'm still able to create feature outside the polygon boundary.

Thanks

0 Kudos
1 Reply
MarkW
by Esri Contributor
Esri Contributor

Hello @SaiPeketi,

 

I was able to get this working by creating a polygon graphic and deleting the sketched graphic when it is not within that polygon. One important note, the default spatial reference for the Sketch widget is 102100, so make sure the boarder polygon has the same spatial reference. 

 

Here is the sample I created, hopefully this is helpful. 

https://codepen.io/MarkW1/pen/xxNORZm

Mark W
0 Kudos