Select to view content in your preferred language

Problem with geometry.getCentroid method

7160
21
Jump to solution
05-05-2016 02:28 PM
DaveSouthern
Deactivated User

I have the following line of code:

this.centerPoint = this.graphic.geometry.getCentroid();

When I run the program and step through the code, the value of geometry.rings is:

[-81.63820933449949,32.72321758156744,-81.6381280506363,32.72321758156744,-81.6381280506363,32.723341259885146,-81.63820933449949,32.723341259885146,-81.63820933449949,32.72321758156744]

But when I examine the X and Y values of the resultant centerpoint variable, they look opposite from what I would expect:

X = 81.6392691466801

Y = -32.7237205172898

Which would move the geometry from the southeastern U.S. to somewhere in the Indian ocean.  Obviously I'm doing something wrong.  Any guesses?

0 Kudos
21 Replies
DaveSouthern
Deactivated User

Well, it seems that reversing the order of the points broke some other things in the app.  It seems some of the shapes we draw were not happy with being reversed.  Back to the drawing board.

0 Kudos
DaveSouthern
Deactivated User

OK.  So the solution turned out to be fairly simple.  Rather than changing the rotation of the graphic before adding it to the map, I simply check the rotation of the graphic selected by the click event and then reverse it's rotation if needed before getting the centroid.  This way I don't affect all the graphics on the map - just the one I'm interested in.

But now I have a different problem going on.  I'll start a new thread to address it. 

0 Kudos