import type { AxiosInstance , AxiosResponse } from 'axios' ; import { ReverseCommand } from '../../../command' ; import { AccuracyEnum } from '../../../model' ; import { ArcgisReverseTransformer } from '../transformer' ; import type { ArcgisReverseQueryInterface } from '../interface' ; import type { ReverseQuery } from '../../../model' ; import { ArcgisCommonCommandMixin } from './mixin' ; link export class ArcgisReverseCommand extends ArcgisCommonCommandMixin ( ReverseCommand ) < ArcgisReverseQueryInterface > { constructor ( httpClient , private readonly token ? ) { super ( httpClient ) ; } static getUrl ( ) { return 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode' ; } protected async buildQuery ( query ) { const featureTypes = [ ] ; switch ( query . accuracy ) { case AccuracyEnum . HOUSE_NUMBER : featureTypes . push ( 'PointAddress' ) ; break ; case AccuracyEnum . STREET_NAME : featureTypes . push ( 'PointAddress' , 'StreetAddress' ) ; break ; case AccuracyEnum . COUNTRY : case AccuracyEnum . STATE : case AccuracyEnum . CITY : featureTypes . push ( 'PointAddress' , 'StreetAddress' , 'Locality' ) ; break ; default : featureTypes . push ( 'PointAddress' ) ; } return { token : this . token , forStorage : ! ! this . token , location : `${ query . lon },${ query . lat }` , featureTypes : featureTypes . join ( ',' ) , maxLocations : query . limit , langCode : query . language , locationType : 'rooftop' , f : 'json' , } ; } protected async parseResponse ( response ) { if ( ! response . data . address || ! response . data . location ) { return [ ] ; } const raw = response . data ; return [ new ArcgisReverseTransformer ( raw ) ] ; } }