Array position from the coordinate system
64-bitThe latitude and longitude of the middle of the array's region.
c = mean of corners; (lon, lat) = toLonLat(c); rounded to 1e-5°
The corner mean is accumulated as x / n per corner in 64-bit numbers. The result is rounded to 5 decimals of a degree before it is returned, so positions are kept to about 1 m.
export async function crsSite(project, poly) {
const crs = project.state.crs;
if (!crs || !poly?.length) return null;
try {
const { frame } = await import('./crs.js');
const c = poly.reduce((m, p) => ({ x: m.x + p.x / poly.length, y: m.y + p.y / poly.length }), { x: 0, y: 0 });
const [lon, lat] = frame(crs).toLonLat(c.x, c.y);
return Number.isFinite(lat) && Number.isFinite(lon) ? { lat: Math.round(lat * 1e5) / 1e5, lon: Math.round(lon * 1e5) / 1e5 } : null;
} catch { return null; }
}