12345678910111213141516171819202122232425 |
- /*
- * L.PolygonUtil contains different utility functions for Polygons.
- */
- L.PolygonUtil = {
- // Ported from the OpenLayers implementation. See https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Geometry/LinearRing.js#L270
- geodesicArea: function (latLngs) {
- var pointsCount = latLngs.length,
- area = 0.0,
- d2r = L.LatLng.DEG_TO_RAD,
- p1, p2;
- if (pointsCount > 2) {
- for (var i = 0; i < pointsCount; i++) {
- p1 = latLngs[i];
- p2 = latLngs[(i + 1) % pointsCount];
- area += ((p2.lng - p1.lng) * d2r) *
- (2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r));
- }
- area = area * 6378137.0 * 6378137.0 / 2.0;
- }
- return Math.abs(area);
- }
- };
|