forked from polka_billy/porridger
12
front/src/api/osmAddress/index.ts
Normal file
12
front/src/api/osmAddress/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { LatLng } from 'leaflet'
|
||||
import { OsmAddressResponse } from './types'
|
||||
|
||||
const initialOsmAddress = ''
|
||||
|
||||
const composeOsmAddressURL = (addressPosition: LatLng) =>
|
||||
`${location.protocol}//nominatim.openstreetmap.org/reverse?format=json&accept-language=ru&lat=${addressPosition.lat}&lon=${addressPosition.lng}`
|
||||
|
||||
const processOsmAddress = (data: OsmAddressResponse): string =>
|
||||
data.display_name
|
||||
|
||||
export { initialOsmAddress, composeOsmAddressURL, processOsmAddress }
|
17
front/src/api/osmAddress/types.ts
Normal file
17
front/src/api/osmAddress/types.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { isObject } from '../../utils/types'
|
||||
|
||||
type OsmAddressResponse = {
|
||||
display_name: string
|
||||
}
|
||||
|
||||
const isOsmAddressResponse = (obj: unknown): obj is OsmAddressResponse => isObject(obj, {
|
||||
'display_name': 'string',
|
||||
})
|
||||
|
||||
export type {
|
||||
OsmAddressResponse,
|
||||
}
|
||||
|
||||
export {
|
||||
isOsmAddressResponse,
|
||||
}
|
Reference in New Issue
Block a user