This commit is contained in:
parent
803dd84858
commit
d53e3e56b5
@ -1,61 +1,96 @@
|
|||||||
|
|
||||||
import { getGeoLine } from "../types/geom";
|
import { getGeoLine } from "../types/geom";
|
||||||
import * as api from "../api";
|
import * as api from "../api";
|
||||||
|
|
||||||
const filter_existing = function (tpe: "nominatim" | "travel", leg: leg, r: geoloc[]) {
|
const filter_existing = function (
|
||||||
|
tpe: "nominatim" | "travel",
|
||||||
|
leg: leg,
|
||||||
|
r: geoloc[]
|
||||||
|
) {
|
||||||
switch (tpe) {
|
switch (tpe) {
|
||||||
case 'nominatim':
|
case "nominatim":
|
||||||
return r.filter(e => {
|
return r.filter((e) => {
|
||||||
if (leg.hotel && leg.hotel.osm_id == e.osm_id) return false;
|
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.restaurants.find((i) => i.osm_id == e.osm_id))
|
||||||
if (leg.places.activities.find(i => i.osm_id == e.osm_id)) return false;
|
return false;
|
||||||
return true
|
if (leg.places.activities.find((i) => i.osm_id == e.osm_id))
|
||||||
})
|
return false;
|
||||||
case 'travel':
|
return true;
|
||||||
console.log(r)
|
});
|
||||||
return r.filter(e => {
|
case "travel":
|
||||||
if (leg.travel.find(i => `${(e as any).from}->${(e as any).to}` == `${(i as any).from}->${(i as any).to}`)) return false;
|
console.log(r);
|
||||||
return true
|
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[]) {
|
const process_results = function (tpe: "nominatim" | "travel", r: geoloc[]) {
|
||||||
switch (tpe) {
|
switch (tpe) {
|
||||||
case 'nominatim':
|
case "nominatim":
|
||||||
return r.map((rr) => {
|
return r.map((rr) => {
|
||||||
rr.latlon = [parseFloat((rr as any).lat), parseFloat((rr as any).lon)];
|
rr.latlon = [
|
||||||
|
parseFloat((rr as any).lat),
|
||||||
|
parseFloat((rr as any).lon),
|
||||||
|
];
|
||||||
rr.title = (rr as any).display_name.split(",")[0];
|
rr.title = (rr as any).display_name.split(",")[0];
|
||||||
return rr;
|
return rr;
|
||||||
});
|
});
|
||||||
case 'travel':
|
case "travel":
|
||||||
console.log(r)
|
console.log(r);
|
||||||
return r.map(el => {
|
return r.map((el) => {
|
||||||
(el as any).path = getGeoLine(
|
(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]);
|
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";
|
(el as any).type = "flight";
|
||||||
return el;
|
return el;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var _search_set_results: (...arg: any[]) => any;
|
var _search_set_results: (...arg: any[]) => any;
|
||||||
export const set_search_set_results = function (f: (...arg: any[]) => any) {
|
export const set_search_set_results = function (f: (...arg: any[]) => any) {
|
||||||
_search_set_results = f;
|
_search_set_results = f;
|
||||||
}
|
};
|
||||||
export const search_nominatim = api.throttle(
|
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) => {
|
f: string,
|
||||||
r = process_results('nominatim', r)
|
q: string,
|
||||||
r = filter_existing('nominatim', leg, r)
|
bb: [[number, number], [number, number]],
|
||||||
_search_set_results(r)
|
leg: leg
|
||||||
}), 1000);
|
) =>
|
||||||
|
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(
|
export const search_flight = api.throttle(
|
||||||
(f: string, q: string, leg: leg) =>
|
(f: string, q: string, leg: leg) =>
|
||||||
api.query_flight(q).then((r) => {
|
api.query_flight(q).then((r) => {
|
||||||
r = process_results('travel', r)
|
r = process_results("travel", r);
|
||||||
r = filter_existing('travel', leg, r)
|
r = filter_existing("travel", leg, r);
|
||||||
_search_set_results(r)
|
_search_set_results(r);
|
||||||
}), 2000)
|
}),
|
||||||
|
3000
|
||||||
|
);
|
||||||
|
@ -141,11 +141,12 @@ const app = new Vue({
|
|||||||
},
|
},
|
||||||
|
|
||||||
drawer_click_item: function (item) {
|
drawer_click_item: function (item) {
|
||||||
|
const tpe = this.query.type
|
||||||
this.search_set_clear(item ? true : false);
|
this.search_set_clear(item ? true : false);
|
||||||
this.drawer_hover_item();
|
this.drawer_hover_item();
|
||||||
if (item) {
|
if (item) {
|
||||||
item.step = -1;
|
item.step = -1;
|
||||||
journey_add_place(this.journey, this.query.type, item)
|
journey_add_place(this.journey, tpe, item)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user