| |
| |
| |
| |
| |
| |
| |
| import type { FeatureCollection } from 'geojson'; |
|
|
| const EMPTY: FeatureCollection = { type: 'FeatureCollection', features: [] }; |
|
|
| async function fetchFc(url: string): Promise<FeatureCollection> { |
| try { |
| const r = await fetch(url); |
| if (!r.ok) return EMPTY; |
| const j = (await r.json()) as FeatureCollection; |
| if (!j || j.type !== 'FeatureCollection') return EMPTY; |
| return j; |
| } catch { |
| return EMPTY; |
| } |
| } |
|
|
| export async function fetchSandy(lat: number, lon: number, r = 1500): Promise<FeatureCollection> { |
| return fetchFc(`/api/layers/sandy?lat=${lat}&lon=${lon}&r=${r}`); |
| } |
|
|
| export async function fetchDep(lat: number, lon: number, r = 1500): Promise<FeatureCollection> { |
| return fetchFc(`/api/layers/dep_extreme_2080?lat=${lat}&lon=${lon}&r=${r}`); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export async function fetchPrithviSynthetic( |
| lat: number, |
| lon: number, |
| r = 1500 |
| ): Promise<FeatureCollection> { |
| return fetchFc(`/api/layers/prithvi_water?lat=${lat}&lon=${lon}&r=${r}`); |
| } |
|
|
| |
| |
| |
| |
| |
| export async function fetchSandyNta(code: string): Promise<FeatureCollection> { |
| return fetchFc(`/api/layers/sandy_clipped?code=${encodeURIComponent(code)}`); |
| } |
|
|
| export async function fetchDepNta( |
| code: string, |
| scenario: 'dep_extreme_2080' | 'dep_moderate_2050' | 'dep_moderate_current' = 'dep_extreme_2080' |
| ): Promise<FeatureCollection> { |
| return fetchFc(`/api/layers/dep_clipped?code=${encodeURIComponent(code)}&scenario=${scenario}`); |
| } |
|
|
| export async function fetchNtaPolygon(code: string): Promise<FeatureCollection> { |
| return fetchFc(`/api/layers/nta?code=${encodeURIComponent(code)}`); |
| } |
|
|
| interface FloodNetSensor { |
| type: 'Feature'; |
| geometry: { type: 'Point'; coordinates: [number, number] }; |
| properties: { n_events_3y?: number; peak_depth_mm?: number; deployment_id?: string; name?: string; [k: string]: unknown }; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function fetchIdaHwm(lat: number, lon: number, r = 1500): Promise<FeatureCollection> { |
| return fetchFc(`/api/layers/ida_hwm?lat=${lat}&lon=${lon}&r=${r}`); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function fetchProxyDots( |
| lat: number, |
| lon: number, |
| r = 1500 |
| ): Promise<FeatureCollection> { |
| try { |
| const res = await fetch(`/api/floodnet_near?lat=${lat}&lon=${lon}&r=${r}`); |
| if (!res.ok) return EMPTY; |
| const j = (await res.json()) as FeatureCollection; |
| |
| const features = j.features.map((f) => { |
| const p = (f as FloodNetSensor).properties ?? {}; |
| return { |
| ...f, |
| properties: { |
| ...p, |
| count: typeof p.n_events_3y === 'number' ? p.n_events_3y : 1 |
| } |
| }; |
| }); |
| return { type: 'FeatureCollection', features }; |
| } catch { |
| return EMPTY; |
| } |
| } |
|
|