feat: add global weather support
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { MeteoStationPosition, SynopStation } from "@/types/imgw";
|
||||
import type { LocationSearchResult, SelectedLocation } from "@/types/location";
|
||||
import { getCountyTerytForLocation } from "@/lib/warning-regions";
|
||||
import { getWeatherRegionForCountryCode } from "@/types/weather-region";
|
||||
|
||||
const stationAliases: Record<string, string> = {
|
||||
gdansk: "gdanskrebiechowo",
|
||||
@@ -64,6 +65,12 @@ export function findNearestSynopStation(
|
||||
name: location.name,
|
||||
province: location.province,
|
||||
district: location.district,
|
||||
country: "Polska",
|
||||
countryCode: "PL",
|
||||
admin1: location.province,
|
||||
admin2: location.district,
|
||||
timezone: "Europe/Warsaw",
|
||||
region: "PL",
|
||||
countyTeryt: getCountyTerytForLocation(location.province, location.district, location.name),
|
||||
latitude: location.latitude,
|
||||
longitude: location.longitude,
|
||||
@@ -72,3 +79,35 @@ export function findNearestSynopStation(
|
||||
distanceKm: Math.round(nearest.distanceKm),
|
||||
};
|
||||
}
|
||||
|
||||
export function createSelectedLocation(
|
||||
location: Pick<LocationSearchResult, "name" | "province" | "district" | "country" | "countryCode" | "admin1" | "admin2" | "timezone" | "region" | "latitude" | "longitude">,
|
||||
stations: LocatedSynopStation[],
|
||||
): SelectedLocation {
|
||||
const countryCode = location.countryCode?.toUpperCase() ?? null;
|
||||
const region = location.region ?? getWeatherRegionForCountryCode(countryCode);
|
||||
const nearest = region === "PL"
|
||||
? stations.reduce<{ station: LocatedSynopStation; distanceKm: number } | null>((best, station) => {
|
||||
const distance = distanceKm(location.latitude, location.longitude, station.latitude, station.longitude);
|
||||
return !best || distance < best.distanceKm ? { station, distanceKm: distance } : best;
|
||||
}, null)
|
||||
: null;
|
||||
|
||||
return {
|
||||
name: location.name,
|
||||
province: location.province,
|
||||
district: location.district,
|
||||
country: location.country,
|
||||
countryCode,
|
||||
admin1: location.admin1,
|
||||
admin2: location.admin2,
|
||||
timezone: location.timezone,
|
||||
region,
|
||||
countyTeryt: region === "PL" ? getCountyTerytForLocation(location.province, location.district, location.name) : null,
|
||||
latitude: location.latitude,
|
||||
longitude: location.longitude,
|
||||
stationId: nearest?.station.id ?? null,
|
||||
stationName: nearest?.station.name ?? null,
|
||||
distanceKm: nearest ? Math.round(nearest.distanceKm) : null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user