AnsweredAssumed Answered

When I click on a feature in my feature layer, what is being returned to me?

Question asked by MollyKFoley on May 2, 2018
Latest reply on May 2, 2018 by kenbuja

I realize this is a pretty vague question, but I'm having trouble wrapping my brain around it. Say I have a feature layer loaded up, it's made up of polygons. If I click on the one of the polygons, the blue selection outline shows up to indicate which one I have clicked on, and I assume some sort of object is being returned to me. What is it and how do I access it? By default each map has a GraphicsLayer so I *think* the object being returned is a graphic. I'd like to learn how to access the geometry of it so I can start doing simple calculations like acreage on whatever polygon the user has clicked. 

 

It appears map.graphics will return an array of the graphics that make up the GL in your map (of which I only have the default, I have not added any of my own). If I were to click on a polygon, would you have to use the method .getSelectedFeatures() or something to get the single graphic of interest? Or would you do something like map.graphics[0]? When I have tried

 

console.log(map.graphics[0]);

I get "undefined" in the console. Though if I do console.log(map.graphics) I can see there is 1 graphic in the array with an index of 0. I'm just not sure where to go from here.

 

If I can get the graphic then I can use the geometry property to start working with it.

Outcomes