- Implemented StopsMap component to display bus stops on a map using MapLibre GL. - Integrated walking directions feature in WalkingDirections component to calculate routes from user location to selected bus stop. - Added geo utility functions for coordinate validation and distance calculation. - Created route grouping and stop filtering logic in routeGroups module. - Developed custom hooks for managing stop routes with React Query. - Added tests for routing and stop functionalities to ensure reliability.
11 lines
550 B
JavaScript
11 lines
550 B
JavaScript
// A missing/invalid pair must never become a marker at (0, 0).
|
|
export function coordinates(latitude, longitude) {
|
|
const number = (value, limit) => {
|
|
if ((typeof value !== 'number' && typeof value !== 'string') || String(value).trim() === '') return undefined;
|
|
const parsed = Number(value);
|
|
return Number.isFinite(parsed) && Math.abs(parsed) <= limit ? parsed : undefined;
|
|
};
|
|
const lat = number(latitude, 90), lon = number(longitude, 180);
|
|
return lat === undefined || lon === undefined ? {} : { latitude: lat, longitude: lon };
|
|
}
|