Select to view content in your preferred language

What is the event thrown by the Lasso Seletion Tool in the Sketch Widget?

1152
4
08-25-2023 09:54 AM
AndrewMurdoch1
Frequent Contributor

Good Day

I have a user who wants to do a reasonably complex selection using the Sketch Widget.  Currently, I'm exposing the Draw Polygon, Rectangle and Circle functions, which react to the "create" event:

 

this._sketchWidget.on("create", async (event) => {})

 

Which is fine, that works and I can select the map segment using those thee tools.  The point selector responds to my "click" handler, which is also working properly, but what does the Lasso Tool throw for an event? 

It's not a click event, it's not the Sketch View create or update event, and according to the documentation, none of the other events would make any sense:

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html#events-summar...

Just so we're clear, this is the tool I'm talking about:

image.png


Are there any examples to show this feature working? 

Thanks

0 Kudos
4 Replies
AndrewMurdoch1
Frequent Contributor

Got it!  Use a pointer-down, and pointer-up event, with a set flag:

this._view.on("pointer-down", (event) => {
  this._view.hitTest(event).then((response) => {
    if (response.results.length && this._sketchWidget.activeTool === 'lasso-selection') {
      this.lassoSet = true;
    }
  });
});

this._view.on("pointer-up", (event) => {
  this._view.hitTest(event).then((response) => {
    if (response.results.length && this.lassoSet) {
      this.lassoSet = false;

      console.log('Response from Lasso Selection');
      console.log(response);
    }
  });
});

 
Now I have a list of selected assets, so I can query them 🙂 - Hope this helps someone!

Thanks

DanielScholes
Occasional Contributor

Hi Andrew, This has been quite helpful. I'm having trouble retrieving the geometry of the lasso selection. Any suggestions on that?

Thanks in advance!

Dan

0 Kudos
AaronFischer1
New Contributor

hopefully not too cryptic but on the code above on line 13 put something like:

const geom - response.results[2].graphic.geometry;
 
this worked for me to do a selection by the lasso polygon geometry
DanielScholes
Occasional Contributor

Hi Aaron. Thanks for the tip. I'm making progress with that.

0 Kudos