updated to proxy loaction search from museum
This commit is contained in:
parent
ccfcc74299
commit
bc044800ae
|
@ -126,7 +126,7 @@ export default function SearchBar(props: Props) {
|
||||||
({
|
({
|
||||||
type: SuggestionType.LOCATION,
|
type: SuggestionType.LOCATION,
|
||||||
value: searchResult.bbox,
|
value: searchResult.bbox,
|
||||||
label: searchResult.placeName,
|
label: searchResult.place,
|
||||||
} as Suggestion)
|
} as Suggestion)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import HTTPService from './HTTPService';
|
import HTTPService from './HTTPService';
|
||||||
import * as chrono from 'chrono-node';
|
import * as chrono from 'chrono-node';
|
||||||
|
import { getEndpoint } from 'utils/common/apiUtil';
|
||||||
|
|
||||||
|
const ENDPOINT = getEndpoint();
|
||||||
|
|
||||||
const KM_IN_DEGREE = 0.01;
|
|
||||||
export type Bbox = [number, number, number, number];
|
export type Bbox = [number, number, number, number];
|
||||||
export interface LocationSearchResponse {
|
export interface LocationSearchResponse {
|
||||||
placeName: string;
|
place: string;
|
||||||
bbox: Bbox;
|
bbox: Bbox;
|
||||||
}
|
}
|
||||||
export const getMapboxToken = () => {
|
export const getMapboxToken = () => {
|
||||||
|
@ -16,26 +18,11 @@ export function parseHumanDate(humanDate: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchLocation(
|
export async function searchLocation(
|
||||||
location: string
|
searchPhrase: string
|
||||||
): Promise<LocationSearchResponse[]> {
|
): Promise<LocationSearchResponse[]> {
|
||||||
const resp = await HTTPService.get(
|
const resp = await HTTPService.get(`${ENDPOINT}/search/location`, {
|
||||||
`https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURI(
|
query: searchPhrase,
|
||||||
location
|
limit: 4,
|
||||||
)}.json`,
|
});
|
||||||
{ access_token: getMapboxToken(), limit: 4 }
|
return resp.data;
|
||||||
);
|
|
||||||
|
|
||||||
return resp.data.features.length == 0
|
|
||||||
? new Array<LocationSearchResponse>()
|
|
||||||
: resp.data.features.map((feature) => ({
|
|
||||||
placeName: feature.place_name,
|
|
||||||
bbox:
|
|
||||||
feature.bbox ??
|
|
||||||
([
|
|
||||||
feature.center[0] - KM_IN_DEGREE,
|
|
||||||
feature.center[1] - KM_IN_DEGREE,
|
|
||||||
feature.center[0] + KM_IN_DEGREE,
|
|
||||||
feature.center[1] + KM_IN_DEGREE,
|
|
||||||
] as Bbox),
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue