import type { LatLngLiteral } from 'leaflet' ; import joinUrl from '../../../shared/utils/joinUrl' ; import environment from '../../../environment' ; import { fetchProxy } from '../../../shared/utils/api/api' ; import type { PanoramaThumbnail } from './types' ; export interface FetchPanoramaOptions { default width ? : number ; default fov ? : number ; default horizon ? : number ; default aspect ? : number ; default radius ? : number ; } type RawResponse = { pano_id : string ; heading : number ; url : string ; } | [ ] ; param location param options export async function getPanoramaThumbnail ( location , options ? ) { const searchParams = new URLSearchParams ( { lat : location . lat . toString ( ) , lon : location . lng . toString ( ) , } ) ; if ( options ?. width ) { searchParams . set ( 'width' , options ?. width . toString ( ) ) ; } if ( options ?. fov ) { searchParams . set ( 'fov' , options ?. fov . toString ( ) ) ; } if ( options ?. horizon ) { searchParams . set ( 'horizon' , options ?. horizon . toString ( ) ) ; } if ( options ?. aspect ) { searchParams . set ( 'aspect' , options ?. aspect . toString ( ) ) ; } if ( options ?. radius ) { searchParams . set ( 'radius' , options ?. radius . toString ( ) ) ; } const response = await fetchProxy < RawResponse > ( `${ joinUrl ( [ environment . API_ROOT , 'panorama/thumbnail' ] ) }?${ searchParams . toString ( ) }` ) ; return transformResponse ( response ) ; } function transformResponse ( response ) { if ( response instanceof Array ) { return null ; } return response ; }