Click event in drawn polygon

1208
2
Jump to solution
05-22-2020 08:15 AM
ThafnySoares
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)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
ThafnySoares
New Contributor III

Thanks!!! 

0 Kudos