Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (sArea === 0) {
return centre;
} else {
// Compute the signed area, and factorize 1/6A
var area = sArea * 0.5;
var areaFactor = 1 / (6 * area);
// Compute the final coordinates, adding back the values that have been neutralized
return point([
translation[0] + areaFactor * sx,
translation[1] + areaFactor * sy
], options.properties);
}
default:
// Not a polygon: Compute the convex hull and work with that
var hull = convex(geojson);
if (hull) return centerOfMass(hull, {properties: options.properties});
// Hull is empty: fallback on the centroid
else return centroid(geojson, {properties: options.properties});
}
}
}).then((data) => {
const vertices = data.features[0].geometry.coordinates[0];
const pointsArray = [];
// convert vertices to turf.js points
vertices.forEach(vertex => pointsArray.push(point(vertex)));
// apply convex hull computation
const hull = convex(featureCollection(pointsArray));
return hull.geometry.coordinates[0];
}).catch(() => false);
};