dev merge (#163)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: soraefir Co-authored-by: sora-ext Reviewed-on: #163
This commit is contained in:
61
src/client/helper/api.ts
Normal file
61
src/client/helper/api.ts
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
import { getGeoLine } from "../types/geom";
|
||||
import * as api from "../api";
|
||||
|
||||
const filter_existing = function (tpe: "nominatim" | "travel", leg: leg, r: geoloc[]) {
|
||||
switch (tpe) {
|
||||
case 'nominatim':
|
||||
return r.filter(e => {
|
||||
if (leg.hotel && leg.hotel.osm_id == e.osm_id) return false;
|
||||
if (leg.places.restaurants.find(i => i.osm_id == e.osm_id)) return false;
|
||||
if (leg.places.activities.find(i => i.osm_id == e.osm_id)) return false;
|
||||
return true
|
||||
})
|
||||
case 'travel':
|
||||
console.log(r)
|
||||
return r.filter(e => {
|
||||
if (leg.travel.find(i => `${(e as any).from}->${(e as any).to}` == `${(i as any).from}->${(i as any).to}`)) return false;
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const process_results = function (tpe: "nominatim" | "travel", r: geoloc[]) {
|
||||
switch (tpe) {
|
||||
case 'nominatim':
|
||||
return r.map((rr) => {
|
||||
rr.latlon = [parseFloat((rr as any).lat), parseFloat((rr as any).lon)];
|
||||
rr.title = (rr as any).display_name.split(",")[0];
|
||||
return rr;
|
||||
});
|
||||
case 'travel':
|
||||
console.log(r)
|
||||
return r.map(el => {
|
||||
(el as any).path = getGeoLine(
|
||||
{ lat: (el as any).from_geo.lat, lng: (el as any).from_geo.lon },
|
||||
{ lat: (el as any).to_geo.lat, lng: (el as any).to_geo.lon }, { dist: 2_500_000 }).map(v => [v.lat, v.lng]);
|
||||
(el as any).type = "flight";
|
||||
return el;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var _search_set_results: (...arg: any[]) => any;
|
||||
export const set_search_set_results = function (f: (...arg: any[]) => any) {
|
||||
_search_set_results = f;
|
||||
}
|
||||
export const search_nominatim = api.throttle(
|
||||
(f: string, q: string, bb: [[number, number], [number, number]], leg: leg) =>
|
||||
api.query_nominatim(q, bb, api.get_filter(f)).catch((_err) => console.log(_err)).then((r) => {
|
||||
r = process_results('nominatim', r)
|
||||
r = filter_existing('nominatim', leg, r)
|
||||
_search_set_results(r)
|
||||
}), 1000);
|
||||
|
||||
export const search_flight = api.throttle(
|
||||
(f: string, q: string, leg: leg) =>
|
||||
api.query_flight(q).then((r) => {
|
||||
r = process_results('travel', r)
|
||||
r = filter_existing('travel', leg, r)
|
||||
_search_set_results(r)
|
||||
}), 2000)
|
Reference in New Issue
Block a user