Vite + TypeScript PWA that mirrors the Android app's core features: - Pre-processed shelter data (build-time UTM33N→WGS84 conversion) - Leaflet map with shelter markers, user location, and offline tiles - Canvas compass arrow (ported from DirectionArrowView.kt) - IndexedDB shelter cache with 7-day staleness check - Service worker with CacheFirst tiles and precached app shell - i18n for en, nb, nn (ported from Android strings.xml) - iOS/Android compass handling with low-pass filter - Respects user map interaction (no auto-snap on pan/zoom) - Build revision cache-breaker for reliable SW updates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
37 lines
921 B
TypeScript
37 lines
921 B
TypeScript
/**
|
|
* Finds the N nearest shelters to a given location.
|
|
* Ported from ShelterFinder.kt in the Android app.
|
|
*/
|
|
|
|
import type { Shelter, ShelterWithDistance } from '../types';
|
|
import { distanceMeters, bearingDegrees } from '../util/distance-utils';
|
|
|
|
/**
|
|
* Find the N nearest shelters to the given location.
|
|
* Returns results sorted by distance (nearest first).
|
|
*/
|
|
export function findNearest(
|
|
shelters: Shelter[],
|
|
latitude: number,
|
|
longitude: number,
|
|
count = 3,
|
|
): ShelterWithDistance[] {
|
|
return shelters
|
|
.map((shelter) => ({
|
|
shelter,
|
|
distanceMeters: distanceMeters(
|
|
latitude,
|
|
longitude,
|
|
shelter.latitude,
|
|
shelter.longitude,
|
|
),
|
|
bearingDegrees: bearingDegrees(
|
|
latitude,
|
|
longitude,
|
|
shelter.latitude,
|
|
shelter.longitude,
|
|
),
|
|
}))
|
|
.sort((a, b) => a.distanceMeters - b.distanceMeters)
|
|
.slice(0, count);
|
|
}
|