Select to view content in your preferred language

<arcgis-sketch> Selection event for lasso / rectangle

293
3
Jump to solution
03-12-2026 12:24 PM
AndrewMurdoch1
Frequent Contributor

Good Day

What is the event thrown by the Lasso selection tool?  

<arcgis-sketch
hide-settings-menu
hide-snapping-controls
hide-create-tools-circle
hide-create-tools-multipoint
hide-create-tools-point
hide-create-tools-rectangle
hide-create-tools-polyline
hide-undo-redo-menu
layout="horizontal"
(arcgisCreate)="onSketchUpdate($event)"
(arcgisPropertyChange)="onSketchUpdate($event)"
(arcgisUpdate)="onSketchUpdate($event)"
[layer]="sketchLayer"
referenceElement="mapElement{{_mapId === 1 ? '1' : '2'}}"
[view]="_view">
</arcgis-sketch>

The property change event seems to throw something, but not the create or update event, so once I finish drawing how do I get the area I just made, so I can run the intersect check?  

Thanks

0 Kudos
1 Solution

Accepted Solutions
WesleyO
Esri Contributor

Hi @AndrewMurdoch1 ,

After a selection is made, the arcgisUpdate event is triggered. It's important to note that this event is also fired when you update the selected graphic or when you unselect the current graphic. To ensure that your function runs right after the graphic is selected (and not updated or unselected), check that the event's state property is "start"

You can find more details about the arcgisUpdate event here: https://developers.arcgis.com/javascript/latest/references/core/widgets/Sketch/types/#UpdateEvent

I've also created a simple codepen that demonstrates this. Create a polygon to see the arcgisCreate event. Then, select the polygon to observe that the arcgisUpdate event being called.

Codepen: https://codepen.io/woriginales/pen/YPGNZmj

Let me know if this helps.

View solution in original post

3 Replies
WesleyO
Esri Contributor

Hi @AndrewMurdoch1 ,

After a selection is made, the arcgisUpdate event is triggered. It's important to note that this event is also fired when you update the selected graphic or when you unselect the current graphic. To ensure that your function runs right after the graphic is selected (and not updated or unselected), check that the event's state property is "start"

You can find more details about the arcgisUpdate event here: https://developers.arcgis.com/javascript/latest/references/core/widgets/Sketch/types/#UpdateEvent

I've also created a simple codepen that demonstrates this. Create a polygon to see the arcgisCreate event. Then, select the polygon to observe that the arcgisUpdate event being called.

Codepen: https://codepen.io/woriginales/pen/YPGNZmj

Let me know if this helps.

AndrewMurdoch1
Frequent Contributor

Thanks!

That solution is definitely working, so I must have something off on my production code.  Very helpful to have a stable solution. 🙂 

0 Kudos
AndrewMurdoch1
Frequent Contributor

Thanks for the help yesterday, I came up with a solution to my issue.   Basically, I'm trying to select features on StreamLayers / FeatureLayers that are under the Lasso Selection tool.  This is now working, and I'm getting the graphics I need, so if anyone else needs help doing this, try this method.

I'm not sure if there is a better method, but this seems to work.  On another point, that draw tool was only active because of another issue, I'm only using the Sketch component for the Lasso / Rectangular selections.

this.sketchWidgetPointerDownEvent = this._view.on("pointer-down", (event) => {

console.log('Got Pointer Down Event');

const sketch = document.querySelector('arcgis-sketch') as any;
const activeTool = sketch?.activeTool;

console.log('Active Tool: ', activeTool);

if (activeTool !== 'polygon') return;

this._view.hitTest(event).then((response) => {
if (response.results.length) {
this.lassoSet = true;
}
})
});

this.sketchWidgetPointerUpEvent = this._view.on("pointer-up", (event) => {

console.log('Got Pointer Up Event');

this._view.hitTest(event).then((response: any) => {
console.log('Response');
console.log(response);
})
});
0 Kudos