The approach I've been working on is implementing a sinusoidal projection to get x,y coordinates and then use a function to calculate the area of an irregular polygon in a plane. Below is the code I've been working on (the points variable is an array of Cesium Cartesian points that is defined elsewhere in the program).
https://stackoverflow.com/a/4682656/7924630 This was a very useful answer that helped me work on this
function polygonArea(X, Y, numPoints) {
let area = 0; // Accumulates area in the loop
let j = numPoints-1; // The last vertex is the 'previous' one to the first
for (i=0; i<numPoints; i++) {
area = area + (X[j]+X[i]) * (Y[j]-Y[i]);
j = i; //j is previous vertex to i
}
return area/2;
}
let xpoints = [];
let ypoints = [];
let lat_dist = (6371009 * Math.PI) / 180;
var i;
for (i = 0; i < points.length; i++) {
let cartoPoint = Cesium.Cartographic.fromCartesian(points[i]);
let lng = cartoPoint.longitude;
let lat = cartoPoint.latitude;
xpoints[i] = lng * lat_dist * Math.cos(lat);
ypoints[i] = lat * lat_dist;
};
surfaceArea = polygonArea(xpoints, ypoints, xpoints.length);
For some reason this is returning really small values for the area and I can't understand why. For example, I tested this on a rectangle area. The area should be approximately 45m², but it's returning 0.0137m². I've tried following other implementations of this, but haven't been able to find anything useful for native Javascript.