I have declared a line geometry as:

var lineString = new OpenLayers.Geometry.LineString([source,target]);

then I am trying to get the centroid of this lineString as lineString.getCentroid().

But what's returning is a Start Point of the lineString.

So, is there any way to get the real centroid of a LineString?

P.S: I have also looked through this discussion. But couldn't figure out the solution.

  • If I understand your link correctly all you have to do is to call lineString.getCentroid(true) – HimBromBeere Sep 4 '14 at 10:49
  • Thanks for reply. I did the same exactly, but that didn't work. I mean it returns the same starting point. And apologies i didn't mention that here(while posting this question). – Suraj Sep 4 '14 at 14:32
  • Try lineString.getCentroid(weighted)? – Erica Sep 4 '14 at 15:25
  • Hi, the HimBromBeere was right (Thanks!). So the solution is lineString.getCentroid(true). I believe earlier it was not worked because of browser cache. – Suraj Sep 5 '14 at 8:51

As per the link shared in question itself, the solution is to call getCentroid() by passing the true as a parameter. i.e. lineString.getCentroid(true).

Thanks to HimBromBeere for his comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.