MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / centroid

Function centroid

libs/leaflet/leaflet-src.js:6279–6290  ·  view source on GitHub ↗
(coords)

Source from the content-addressed store, hash-verified

6277 * Returns the 'center of mass' of the passed LatLngs.
6278 */
6279 function centroid(coords) {
6280 var latSum = 0;
6281 var lngSum = 0;
6282 var len = 0;
6283 for (var i = 0; i < coords.length; i++) {
6284 var latlng = toLatLng(coords[i]);
6285 latSum += latlng.lat;
6286 lngSum += latlng.lng;
6287 len++;
6288 }
6289 return toLatLng([latSum / len, lngSum / len]);
6290 }
6291
6292 var PolyUtil = {
6293 __proto__: null,

Callers 2

polygonCenterFunction · 0.85
polylineCenterFunction · 0.85

Calls 1

toLatLngFunction · 0.70

Tested by

no test coverage detected