New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getCenter of Polygon (Centroid) #1196
Comments
Nice suggestion, will consider this. Thanks! |
We found a little mistake in the function. Here you can read the small discussion: https://plus.google.com/u/0/108220049326938062364/posts/beV4PQYM58x The problem only exits if the polygon is very small (~5x5meters). This code works with very small polygons too. var pts = this._latlngs; |
Another little improvment: return value should be a L.LatLng() object. return new L.LatLng( |
Just wanted to note that this fn would be very helpful for the mapping I've been doing recently -- would love to see it in Leaflet. |
same here! Love your work... thank you! |
Done as a part of #2290, along with polyline centroids |
Example:
If i want to get draw in the middle of a polygon a icon, i need the center of this polygon.
Samplecode:
L.Polygon.prototype.getCenter = function(){
var pts = this._latlngs;
}
Problem: This code only works for a non-self-intersecting closed polygon
Rectangle: Much easier and no problems with self-intersection!
Source: https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon
The text was updated successfully, but these errors were encountered: