From 70b4da8e2c5ac535447d6376f75aa5d512d7e1db Mon Sep 17 00:00:00 2001 From: kerboul Date: Tue, 31 Mar 2026 15:43:49 +0200 Subject: [PATCH] fix: use spherical polygon formula for isochrone area (Turf.js method) Co-Authored-By: Claude Sonnet 4.6 --- src/renderer/src/components/Legend.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/components/Legend.tsx b/src/renderer/src/components/Legend.tsx index 3234ffe..7f9a953 100644 --- a/src/renderer/src/components/Legend.tsx +++ b/src/renderer/src/components/Legend.tsx @@ -3,16 +3,18 @@ import { useAppStore } from '../store/useAppStore' import { formatDuration, getIsochroneColors } from '../api/ors' function ringAreaKm2(coords: number[][]): number { + const R = 6371 let area = 0 const n = coords.length for (let i = 0; i < n; i++) { const j = (i + 1) % n - area += coords[i][0] * coords[j][1] - area -= coords[j][0] * coords[i][1] + const lon1 = coords[i][0] * Math.PI / 180 + const lat1 = coords[i][1] * Math.PI / 180 + const lon2 = coords[j][0] * Math.PI / 180 + const lat2 = coords[j][1] * Math.PI / 180 + area += (lon2 - lon1) * (2 + Math.sin(lat1) + Math.sin(lat2)) } - area = Math.abs(area) / 2 - const midLat = (coords.reduce((s, c) => s + c[1], 0) / coords.length) * (Math.PI / 180) - return area * 111.32 * 111.32 * Math.cos(midLat) + return Math.abs(area) * R * R / 2 } function featureAreaKm2(f: Feature): number {