Add src/client/api_helper.ts
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
sora-ext 2025-03-04 17:19:11 +01:00
parent 974d0354b4
commit ec8f781e55

41
src/client/api_helper.ts Normal file
View File

@ -0,0 +1,41 @@
import { getGeoLine } from "./types/geom";
export 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
})
}
}
export 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;
});
}
}