carto: extract polygonArea helper

This commit is contained in:
Paul Chavard 2018-10-13 10:55:40 +02:00
parent 53c6003d27
commit 25e71634e7

View file

@ -0,0 +1,19 @@
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])]
}
};
}