demarches-normaliennes/app/javascript/shared/polygon_area.js
2018-10-23 09:35:25 +02:00

19 lines
393 B
JavaScript

import area from '@turf/area';
export default function polygonArea(latLngs) {
return area({
type: 'FeatureCollection',
features: latLngs.map(featurePolygonLatLngs)
});
}
function featurePolygonLatLngs(latLngs) {
return {
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [latLngs.map(({ lng, lat }) => [lng, lat])]
}
};
}