This commit is contained in:
Jesse Winton
2025-04-15 08:52:43 -04:00
parent 569970f1e0
commit 3115a064e9
2 changed files with 28 additions and 7 deletions

View File

@@ -13,11 +13,18 @@ export const latLongToSvgPosition = ({
}: Coordinates & { width: number; height: number }) => {
const { west, east, north, south } = MAP_BOUNDS;
const lngRatio = (longitude - west) / (east - west);
const latRatio = (latitude - south) / (north - south);
// Handle longitude wrapping for coordinates crossing the date line
let lng = longitude;
if (lng < west) lng += 360;
else if (lng > east) lng -= 360;
const x = Math.max(0, Math.min(1, lngRatio)) * 100;
const y = Math.max(0, Math.min(1, 1 - latRatio)) * 100;
// Calculate position as percentage of the map bounds
const lngRatio = (lng - west) / (east - west);
const latRatio = (north - latitude) / (north - south);
// Convert to percentages clamped between 0-100
const x = Math.max(0, Math.min(100, lngRatio * 100));
const y = Math.max(0, Math.min(100, latRatio * 100));
return { x, y };
};