UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

21 lines (20 loc) 756 B
/** * Find the area of a linestring. No projection is assumed * @param input - the linestring as either a VectorFeature, VectorLineStringGeometry, or raw VectorLineString * @returns - the area of the linestring. Positive if the linestring is counter-clockwise, negative otherwise */ export function lineArea(input) { const vectorLines = 'geometry' in input ? input.geometry.coordinates : 'coordinates' in input ? input.coordinates : input; let area = 0; const numPoints = vectorLines.length; let j = numPoints - 1; for (let i = 0; i < numPoints; i++) { area += (vectorLines[j].x + vectorLines[i].x) * (vectorLines[j].y - vectorLines[i].y); j = i; } return area / 2; }