export type GetApiV1ElevationArgs = {longitude: number, latitude: number, dataset?: ('ANADEM' | 'ArcticDEM10m' | 'ArcticDEM2m' | 'ArcticDEM32m' | 'AW3D30' | 'AW3D30_E' | 'CA_MRDEM_DSM' | 'CA_MRDEM_DTM' | 'COP30' | 'COP90' | 'EU_DTM' | 'GEBCOIceTopo' | 'GEBCOSubIceTopo' | 'GEDI_L3' | 'GEDTM30' | 'LINZ1m_DSM' | 'LINZ1m_DTM' | 'NASADEM' | 'REMA10m' | 'REMA2m' | 'REMA32m' | 'SRTM15Plus' | 'SRTM_GL1' | 'SRTM_GL1_Ellip' | 'SRTM_GL3' | 'USGS10m' | 'USGS30m') | undefined, API_Key: string}; export type GetApiV1ElevationOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Returns elevation data for a specified latitude and longitude, derived from topography datasets hosted by OpenTopography. API also provides option to specify the topography dataset to be used. * * GET /v1/elevation */ export const getApiV1Elevation = async (args: GetApiV1ElevationArgs, options: GetApiV1ElevationOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.longitude != null) query.append("longitude", String(args.longitude)) if (args.latitude != null) query.append("latitude", String(args.latitude)) if (args.dataset != null) query.append("dataset", String(args.dataset)) if (args.API_Key != null) query.append("API_Key", String(args.API_Key)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/elevation${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };