export type RoadClass = 'motorway' | 'trunk' | 'primary' | 'secondary' | 'tertiary' | 'unclassified' | 'residential' | 'service_other'; export type SearchFilter = {min_road_class?: RoadClass | undefined, max_road_class?: RoadClass | undefined, exclude_tunnel?: boolean | undefined, exclude_bridge?: boolean | undefined, exclude_toll?: boolean | undefined, exclude_ramp?: boolean | undefined, exclude_ferry?: boolean | undefined, exclude_restricted?: boolean | undefined, exclude_steps?: boolean | undefined, exclude_closures?: boolean | undefined, level?: number | undefined}; export type Location = {lat: number, lon: number, type?: ('break' | 'through' | 'via' | 'break_through') | undefined, name?: string | undefined, street?: string | undefined, date_time?: string | undefined, heading?: number | undefined, heading_tolerance?: number | undefined, preferred_layer?: number | undefined, node_snap_tolerance?: number | undefined, minimum_reachability?: number | undefined, radius?: number | undefined, search_cutoff?: number | undefined, rank_candidates?: boolean | undefined, preferred_side?: ('same' | 'opposite' | 'either') | undefined, display_lat?: number | undefined, display_lon?: number | undefined, street_side_tolerance?: number | undefined, street_side_max_distance?: number | undefined, street_side_cutoff?: RoadClass | undefined, waiting?: number | undefined, search_filter?: SearchFilter | undefined}; export type ShapeFormat = 'polyline6' | 'polyline5' | 'geojson' | 'no_shape'; export type HeightRequest = {id?: string | undefined, shape?: Array | undefined, encoded_polyline?: string | undefined, shape_format?: ShapeFormat | undefined, range?: boolean | undefined, height_precision?: (0 | 1 | 2) | undefined, resample_distance?: number | undefined}; export type CreateApiHeightArgs = {body: HeightRequest}; export type CreateApiHeightOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * /height * * POST /height */ export const createApiHeight = async (args: CreateApiHeightArgs, options?: CreateApiHeightOptions) => { const {baseUrl = "https://valhalla1.openstreetmap.de", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/height${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };