export type GeoJsonFeature = {type: 'Feature', geometry: {type: string, coordinates: Array}, properties: {[key: string]: unknown}}; export type GeoJsonFeatureCollection = {type: 'FeatureCollection', features: Array}; export type CreateApiV1StaticArgs = {key?: string | undefined, body: GeoJsonFeatureCollection}; export type CreateApiV1StaticOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Static map with GeoJSON * * POST /v1/static * * Also accepts auth: ApiKeyQuery */ export const createApiV1Static = async (args: CreateApiV1StaticArgs, options?: CreateApiV1StaticOptions) => { const {baseUrl = "https://api.latlng.work", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "image/png") if (args.key != null) query.append("key", String(args.key)) if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/static${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 res.blob() };