From d68bbe28f0112288b93f732ab2af1524167d6aa3 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 25 Oct 2025 11:39:00 -0500 Subject: [PATCH] Fix coordinate extraction to handle nested arrays - Add extractCoordinate helper to recursively extract coordinates - Handle coordinates that come as nested arrays like [[lat]] - Log raw coordinate values when validation fails for debugging - Prevents Invalid coordinates errors in console This handles edge cases where coordinates are wrapped in arrays before being passed to the marker creation code. --- assets/js/map.ts | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/assets/js/map.ts b/assets/js/map.ts index 0d20b34..5d99e8d 100644 --- a/assets/js/map.ts +++ b/assets/js/map.ts @@ -1432,12 +1432,13 @@ let MapAPRSMap = { return; } - const lat = parseFloat(data.lat.toString()); - const lng = parseFloat(data.lng.toString()); + // Extract coordinates - handle both direct values and nested arrays + const lat = extractCoordinate(data.lat); + const lng = extractCoordinate(data.lng); // Validate coordinates if (!isValidCoordinate(lat, lng)) { - console.warn("Invalid coordinates for marker:", { id: data.id, lat, lng, callsign: data.callsign }); + console.warn("Invalid coordinates for marker:", { id: data.id, lat, lng, callsign: data.callsign, rawLat: data.lat, rawLng: data.lng }); return; } @@ -2107,6 +2108,32 @@ let MapAPRSMap = { }, }; +// Helper to extract coordinate from various formats (number, string, or nested array) +function extractCoordinate(value: any): number { + // Handle null/undefined + if (value === null || value === undefined) { + return NaN; + } + + // Handle arrays (sometimes coordinates come as nested arrays) + if (Array.isArray(value)) { + // Recursively extract from first element if it's an array + return extractCoordinate(value[0]); + } + + // Handle numbers + if (typeof value === 'number') { + return value; + } + + // Handle strings + if (typeof value === 'string') { + return parseFloat(value); + } + + return NaN; +} + // Helper to validate coordinates function isValidCoordinate(lat: number, lng: number): boolean { return !isNaN(lat) && !isNaN(lng) && lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;