Click event in drawn polygon

79
2
Jump to solution
05-22-2020 08:15 AM
Highlighted
New Contributor III

How can I get the click on a polygon that was drawn using Sketch Widget? I tried hitTest, but it brings several results (points and polygons)

Currently my code looks like this:

view.on("click", function (event) {
   view.hitTest(event.screenPoint).then(function (response) {
      console.log(response.results); //results an array of geometrys
   });
});
Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Esteemed Contributor

Thafny,

   Just loop through the hit test results and look at the response.results array (which is an array of graphics) Each graphic has a layer property. You check if the layer is the same layer id as your polygon layer that you are interested in.

View solution in original post

Reply
0 Kudos
2 Replies
Highlighted
MVP Esteemed Contributor

Thafny,

   Just loop through the hit test results and look at the response.results array (which is an array of graphics) Each graphic has a layer property. You check if the layer is the same layer id as your polygon layer that you are interested in.

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor III

Thanks!!! 

Reply
0 Kudos