carto: extract polygonArea helper
This commit is contained in:
parent
53c6003d27
commit
25e71634e7
1 changed files with 19 additions and 0 deletions
19
app/javascript/old_design/carto/polygon_area.js
Normal file
19
app/javascript/old_design/carto/polygon_area.js
Normal 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])]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue