AnsweredAssumed Answered

Polygon Centroid Incorrect for Small Polygons in 4.4

Question asked by alindley on Sep 22, 2017

I noticed a problem with the calculated centroid of a polygon graphic when you draw a very small polygon.

 

I am trying to add a text graphic to the center of a polygon graphic by grabbing the centroid of the polygon when drawing is complete and creating a simple text symbol with the centroid geometry.

 

The polygonGraphic.geometry.centroid.x (and y) property works perfectly when the polygons cover multiple acres, but the smaller they get, the farther outside the polygon the text labels appear.

 

I put together an example of the problem for reference here:

JS Bin - Collaborative JavaScript Debugging 

*note: you must draw polygons in the clockwise direction*

 

I've also attached a screen grab of the problem.

 

If you zoom in a lot and draw a polygon that is 0 acres, you should notice that the text showing its area is drawn far outside the bounds of the polygon. As far as I can tell this is not a spatial reference issue.

 

The only fix I've found it to use the polygonGraphic.geometry.extent.center.x property instead of the centroid, which works but is not ideal.

 

I know this is kind of a niche problem, but any insight would be much appreciated.

 

Thanks

Outcomes