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.
This commit is contained in:
parent
6e91085535
commit
d68bbe28f0
1 changed files with 30 additions and 3 deletions
|
|
@ -1432,12 +1432,13 @@ let MapAPRSMap = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lat = parseFloat(data.lat.toString());
|
// Extract coordinates - handle both direct values and nested arrays
|
||||||
const lng = parseFloat(data.lng.toString());
|
const lat = extractCoordinate(data.lat);
|
||||||
|
const lng = extractCoordinate(data.lng);
|
||||||
|
|
||||||
// Validate coordinates
|
// Validate coordinates
|
||||||
if (!isValidCoordinate(lat, lng)) {
|
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;
|
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
|
// Helper to validate coordinates
|
||||||
function isValidCoordinate(lat: number, lng: number): boolean {
|
function isValidCoordinate(lat: number, lng: number): boolean {
|
||||||
return !isNaN(lat) && !isNaN(lng) && lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;
|
return !isNaN(lat) && !isNaN(lng) && lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue