diff --git a/router/api.js b/router/api.js index 3366236..c7c421a 100644 --- a/router/api.js +++ b/router/api.js @@ -6,7 +6,7 @@ module.exports = (fastify, opts, done) => { url.searchParams.append('query', req.params.id) url.searchParams.append('limit', 16) url.searchParams.append('type', 'schedule') - fetch(url).then((res) => reply.send(res.data)); + fetch(url).then((res) => reply.send(res.json())); } else { return reply.send([]); } @@ -14,10 +14,20 @@ module.exports = (fastify, opts, done) => { }); fastify.get("/place/:id", async (req, reply) => { if (req.params.id) { - const url = new URL("https://nominatim.openstreetmap.org/"); + const url = new URL("https://nominatim.openstreetmap.org/search"); url.searchParams.append('format', 'jsonv2') url.searchParams.append('q', req.params.id) - fetch(url).then((res) => reply.send(res.data)); + + let bb = JSON.parse(req.query.bb) + if(bb){ + url.searchParams.append('viewbox', `${bb[0][0]},${bb[0][1]},${bb[1][0]},${bb[1][1]}`) + url.searchParams.append('bounded', 1) + } + fetch(url).then((res) => { + if( !res.ok) throw new Error("Nominatim Error") + return res.json() + }).then(res=>{ + reply.send(res)}); } else { return reply.send([]); } diff --git a/src/api.ts b/src/api.ts index 8717b9c..26b5689 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,110 +1,142 @@ export const throttle = (func: () => void, wait: number) => { - let lastTime = 0; - let timeoutId: ReturnType | undefined; - let lastArgs: any[]; + let lastTime = 0; + let timeoutId: ReturnType | undefined; + let lastArgs: any[]; - return function (...args: any[]) { - const now = Date.now(); - lastArgs = args; + return function (...args: any[]) { + const now = Date.now(); + lastArgs = args; - if (now - lastTime >= wait) { - lastTime = now; - func.apply(this, lastArgs); - } else { - if (timeoutId) clearTimeout(timeoutId); - timeoutId = setTimeout(() => { - lastTime = Date.now(); - func.apply(this, lastArgs); - }, wait - (now - lastTime)); - } - }; -} + if (now - lastTime >= wait) { + lastTime = now; + func.apply(this, lastArgs); + } else { + if (timeoutId) clearTimeout(timeoutId); + timeoutId = setTimeout( + () => { + lastTime = Date.now(); + func.apply(this, lastArgs); + }, + wait - (now - lastTime) + ); + } + }; +}; export const load = (id: string) => - fetch("/api/" + id).then(res => { - if (!res.ok) throw new Error('Error ' + res.statusText); - return res.json(); - }).then((res) => { - for (let e of res.main) { - if (e.date_range) { - e.date_range[0] = new Date(e.date_range[0]); - e.date_range[1] = new Date(e.date_range[1]); - } - e.step_title = e.step_title || []; - } - return res; - }) + fetch("/api/" + id) + .then((res) => { + if (!res.ok) throw new Error("Error " + res.statusText); + return res.json(); + }) + .then((res) => { + for (let e of res.main) { + if (e.date_range) { + e.date_range[0] = new Date(e.date_range[0]); + e.date_range[1] = new Date(e.date_range[1]); + } + e.day_title = e.day_title || []; + } + return res; + }); export const save = (id: string, v: journey) => - fetch("/api/" + id, { method: "post", body: JSON.stringify(v) }) - .then(res => { - if (!res.ok) throw new Error('Error ' + res.statusText); - return res.json(); - }).then((_res) => { - console.log("Saved..."); - }) + fetch("/api/" + id, { method: "post", body: JSON.stringify(v) }) + .then((res) => { + if (!res.ok) throw new Error("Error " + res.statusText); + return res.json(); + }) + .then((_res) => { + console.log("Saved..."); + }); export const query_nominatim = ( - q: string, - f: (v: string) => Boolean = () => true, -) => - fetch("/api/place/" + q) - .then((res) => (res.status == 200) ? res.json() : []) - .then((res) => res.filter(f)); + q: string, + bb: any, + f: (v: string) => Boolean = () => true +) => { + let url = new URL("/api/place/" + q, window.location.origin); + url.searchParams.append("id", q); + url.searchParams.append("bb", JSON.stringify(bb)); + return fetch(url) + .then((res) => (res.status == 200 ? res.json() : [])) + .then((res) => res.filter(f)); +}; export const query_flight = (q: string) => - fetch("/api/flight/" + q).then((res) => res.json()); + fetch("/api/flight/" + q).then((res) => res.json()); type NominatimResult = { - type: string; - category: string; - display_name: string; // DEBUG ONLY + type: string; + category: string; + display_name: string; // DEBUG ONLY }; export const is_restauration_type = (e: NominatimResult) => - ["restaurant", "cafe", "pub", "bar", "fast_food", "food_court"].indexOf( - e.type, - ) != -1; + ["restaurant", "cafe", "pub", "bar", "fast_food", "food_court"].indexOf( + e.type + ) != -1; export const is_attraction_type = (e: NominatimResult): boolean => - [ - "tourism", - "leisure", - "place", - "amenity", - "highway", - "historic", - "natural", - "waterway", - ].indexOf(e.category) != -1 || - [ - "place_of_worship", - "national_park", - "nature_reserve", - "protected_area", - ].indexOf(e.type) != -1; + [ + "tourism", + "leisure", + "place", + "amenity", + "highway", + "historic", + "natural", + "waterway", + ].indexOf(e.category) != -1 || + [ + "place_of_worship", + "national_park", + "nature_reserve", + "protected_area", + ].indexOf(e.type) != -1; export const icon_type = (item: NominatimResult): string => { - let t = item.type; - let c = item.category; - let types = { - "utensils": ["restaurant", "cafe", "pub", "bar", "fast_food", "food_court"], - "bed": ["hotel", "hostel", "guest_house"], - "landmark": ["museum", "historic", "place_of_worship", "attraction", "information", "university"], - "mountain": ["peak", "viewpoint"], - "parking": ["parking"], - "water": ["water", "river", "lake", "torrent", "aquarium"], - "building": ["community_center", "locality"], - "archway": ["bridge"], - "tree": ["woodland", "shieling", "national_park", "park", "zoo", "garden", "nature_reserve"], - "dice-five": ["water_park", "theme_park", "casino"], - "": ["?", "neighbourhood", "quarter", "highway"], - } + let t = item.type; + let c = item.category; + let types = { + utensils: [ + "restaurant", + "cafe", + "pub", + "bar", + "fast_food", + "food_court", + ], + bed: ["hotel", "hostel", "guest_house"], + landmark: [ + "museum", + "historic", + "place_of_worship", + "attraction", + "information", + "university", + ], + mountain: ["peak", "viewpoint"], + parking: ["parking"], + water: ["water", "river", "lake", "torrent", "aquarium"], + building: ["community_center", "locality"], + archway: ["bridge"], + tree: [ + "woodland", + "shieling", + "national_park", + "park", + "zoo", + "garden", + "nature_reserve", + ], + "dice-five": ["water_park", "theme_park", "casino"], + "": ["?", "neighbourhood", "quarter", "highway"], + }; - for (let k in types) { - if (types[k].indexOf(t) >= 0 || types[k].indexOf(c) >= 0) - return k; - } - console.log(item.display_name, item.category, item.type); - return "question"; + for (let k in types) { + if (types[k].indexOf(t) >= 0 || types[k].indexOf(c) >= 0) return k; + } + console.log(item.display_name, item.category, item.type); + return "question"; }; diff --git a/src/old.js b/src/old.js index 3a9435d..9e4d8e4 100644 --- a/src/old.js +++ b/src/old.js @@ -37,14 +37,25 @@ const app = new Vue({ } }, methods: { - start_journey: () => window.location.href = "/" + this.journey.id, + start_journey: function(){ window.location.href = "/" + this.journey.id}, + + compute_bb: function(){ + const map = this.$refs.map[0].mapObject; + var bounds = map.getBounds(); + var minLng = bounds.getSouthWest().lng; + var minLat = bounds.getSouthWest().lat; + var maxLng = bounds.getNorthEast().lng; + var maxLat = bounds.getNorthEast().lat; + return [[minLng,minLat],[maxLng,maxLat]] + }, search_nominatim: function (txt, f) { if (txt == "") { this.query.nominatim = []; return Promise.resolve([]); } - return api.query_nominatim(txt, f).catch((err) => []).then((results) => { + let bb = this.journey.leg_get(); + return api.query_nominatim(txt,this.compute_bb(), f).catch((err) => []).then((results) => { results.forEach((r) => { r.latlon = [parseFloat(r.lat), parseFloat(r.lon)]; r.sname = r.display_name.split(",")[0]; diff --git a/template/module/journey_step.pug b/template/module/journey_step.pug index 94e06da..c3498c1 100644 --- a/template/module/journey_step.pug +++ b/template/module/journey_step.pug @@ -7,7 +7,7 @@ div(v-for="(e, idx) in journey.data.main", :key="idx") .input.col-sm-2 input( placeholder="Day title", - v-model="journey.leg_get(idx).step_title[journey.sel_day]" + v-model="journey.leg_get(idx).day_title[journey.sel_day]" ) .col-sm-3 .right.input.col-sm-2 diff --git a/template/module/map.pug b/template/module/map.pug index 51a08db..b7da2cf 100644 --- a/template/module/map.pug +++ b/template/module/map.pug @@ -2,6 +2,7 @@ l-map( :zoom.sync="journey.data.main[idx].map.zoom", :center.sync="journey.data.main[idx].map.center", style="padding-top: 100%" + ref="map" ) l-tile-layer( url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", diff --git a/template/module/view_step.pug b/template/module/view_step.pug index bcb4d82..90daa75 100644 --- a/template/module/view_step.pug +++ b/template/module/view_step.pug @@ -7,7 +7,7 @@ div(v-for="(e, idx) in journey.data.main", :key="idx") i.fas.fa-angle-left span.container span.small {{ journey.data.main[idx].title }} {{ journey.sel_day }} - .text-big.text-gray {{ journey.data.main[idx].step_title[journey.sel_day] }} + .text-big.text-gray {{ journey.data.main[idx].day_title[journey.sel_day] }} .aligner--itemEnd.fright a(href="#next", v-on:click.prevent="journey.day_next()") i.fas.fa-angle-right diff --git a/yarn.lock b/yarn.lock index 3d1e226..9d38d61 100644 --- a/yarn.lock +++ b/yarn.lock @@ -527,13 +527,6 @@ __metadata: languageName: node linkType: hard -"asynckit@npm:^0.4.0": - version: 0.4.0 - resolution: "asynckit@npm:0.4.0" - checksum: 10c0/d73e2ddf20c4eb9337e1b3df1a0f6159481050a5de457c55b14ea2e5cb6d90bb69e004c9af54737a5ee0917fcf2c9e25de67777bbe58261847846066ba75bc9d - languageName: node - linkType: hard - "atomic-sleep@npm:^1.0.0": version: 1.0.0 resolution: "atomic-sleep@npm:1.0.0" @@ -551,17 +544,6 @@ __metadata: languageName: node linkType: hard -"axios@npm:^1.7.9": - version: 1.7.9 - resolution: "axios@npm:1.7.9" - dependencies: - follow-redirects: "npm:^1.15.6" - form-data: "npm:^4.0.0" - proxy-from-env: "npm:^1.1.0" - checksum: 10c0/b7a41e24b59fee5f0f26c1fc844b45b17442832eb3a0fb42dd4f1430eb4abc571fe168e67913e8a1d91c993232bd1d1ab03e20e4d1fee8c6147649b576fc1b0b - languageName: node - linkType: hard - "babel-walk@npm:3.0.0-canary-5": version: 3.0.0-canary-5 resolution: "babel-walk@npm:3.0.0-canary-5" @@ -728,15 +710,6 @@ __metadata: languageName: node linkType: hard -"combined-stream@npm:^1.0.8": - version: 1.0.8 - resolution: "combined-stream@npm:1.0.8" - dependencies: - delayed-stream: "npm:~1.0.0" - checksum: 10c0/0dbb829577e1b1e839fa82b40c07ffaf7de8a09b935cadd355a73652ae70a88b4320db322f6634a4ad93424292fa80973ac6480986247f1734a1137debf271d5 - languageName: node - linkType: hard - "concat-map@npm:0.0.1": version: 0.0.1 resolution: "concat-map@npm:0.0.1" @@ -803,13 +776,6 @@ __metadata: languageName: node linkType: hard -"delayed-stream@npm:~1.0.0": - version: 1.0.0 - resolution: "delayed-stream@npm:1.0.0" - checksum: 10c0/d758899da03392e6712f042bec80aa293bbe9e9ff1b2634baae6a360113e708b91326594c8a486d475c69d6259afb7efacdc3537bfcda1c6c648e390ce601b19 - languageName: node - linkType: hard - "depd@npm:2.0.0": version: 2.0.0 resolution: "depd@npm:2.0.0" @@ -921,18 +887,6 @@ __metadata: languageName: node linkType: hard -"es-set-tostringtag@npm:^2.1.0": - version: 2.1.0 - resolution: "es-set-tostringtag@npm:2.1.0" - dependencies: - es-errors: "npm:^1.3.0" - get-intrinsic: "npm:^1.2.6" - has-tostringtag: "npm:^1.0.2" - hasown: "npm:^2.0.2" - checksum: 10c0/ef2ca9ce49afe3931cb32e35da4dcb6d86ab02592cfc2ce3e49ced199d9d0bb5085fc7e73e06312213765f5efa47cc1df553a6a5154584b21448e9fb8355b1af - languageName: node - linkType: hard - "esbuild@npm:^0.25.0": version: 0.25.0 resolution: "esbuild@npm:0.25.0" @@ -1143,16 +1097,6 @@ __metadata: languageName: node linkType: hard -"follow-redirects@npm:^1.15.6": - version: 1.15.9 - resolution: "follow-redirects@npm:1.15.9" - peerDependenciesMeta: - debug: - optional: true - checksum: 10c0/5829165bd112c3c0e82be6c15b1a58fa9dcfaede3b3c54697a82fe4a62dd5ae5e8222956b448d2f98e331525f05d00404aba7d696de9e761ef6e42fdc780244f - languageName: node - linkType: hard - "foreground-child@npm:^3.1.0": version: 3.3.0 resolution: "foreground-child@npm:3.3.0" @@ -1163,18 +1107,6 @@ __metadata: languageName: node linkType: hard -"form-data@npm:^4.0.0": - version: 4.0.2 - resolution: "form-data@npm:4.0.2" - dependencies: - asynckit: "npm:^0.4.0" - combined-stream: "npm:^1.0.8" - es-set-tostringtag: "npm:^2.1.0" - mime-types: "npm:^2.1.12" - checksum: 10c0/e534b0cf025c831a0929bf4b9bbe1a9a6b03e273a8161f9947286b9b13bf8fb279c6944aae0070c4c311100c6d6dbb815cd955dc217728caf73fad8dc5b8ee9c - languageName: node - linkType: hard - "fs-minipass@npm:^3.0.0": version: 3.0.3 resolution: "fs-minipass@npm:3.0.3" @@ -1698,22 +1630,6 @@ __metadata: languageName: node linkType: hard -"mime-db@npm:1.52.0": - version: 1.52.0 - resolution: "mime-db@npm:1.52.0" - checksum: 10c0/0557a01deebf45ac5f5777fe7740b2a5c309c6d62d40ceab4e23da9f821899ce7a900b7ac8157d4548ddbb7beffe9abc621250e6d182b0397ec7f10c7b91a5aa - languageName: node - linkType: hard - -"mime-types@npm:^2.1.12": - version: 2.1.35 - resolution: "mime-types@npm:2.1.35" - dependencies: - mime-db: "npm:1.52.0" - checksum: 10c0/82fb07ec56d8ff1fc999a84f2f217aa46cb6ed1033fefaabd5785b9a974ed225c90dc72fff460259e66b95b73648596dbcc50d51ed69cdf464af2d237d3149b2 - languageName: node - linkType: hard - "mime@npm:^3": version: 3.0.0 resolution: "mime@npm:3.0.0" @@ -2032,13 +1948,6 @@ __metadata: languageName: node linkType: hard -"pretier@npm:^0.0.1": - version: 0.0.1 - resolution: "pretier@npm:0.0.1" - checksum: 10c0/206f5b353c32a9ad0e38243ad2caf7c8859ef43c975514e1c725088e4925d8b1480f73b96ebfd5ceaa1a563a77a3b8c893db7bb3642585bfa0c635f7ee149885 - languageName: node - linkType: hard - "prettier@npm:^3.5.2": version: 3.5.2 resolution: "prettier@npm:3.5.2" @@ -2081,13 +1990,6 @@ __metadata: languageName: node linkType: hard -"proxy-from-env@npm:^1.1.0": - version: 1.1.0 - resolution: "proxy-from-env@npm:1.1.0" - checksum: 10c0/fe7dd8b1bdbbbea18d1459107729c3e4a2243ca870d26d34c2c1bcd3e4425b7bcc5112362df2d93cc7fb9746f6142b5e272fd1cc5c86ddf8580175186f6ad42b - languageName: node - linkType: hard - "pstree.remy@npm:^1.1.8": version: 1.1.8 resolution: "pstree.remy@npm:1.1.8" @@ -2676,11 +2578,9 @@ __metadata: "@fastify/view": "npm:^10.0.0" "@prettier/plugin-pug": "npm:^3.0.0" "@types/node": "npm:^22.13.5" - axios: "npm:^1.7.9" esbuild: "npm:^0.25.0" fastify: "npm:^5.0.0" nodemon: "npm:^3.0.1" - pretier: "npm:^0.0.1" prettier: "npm:^3.5.2" pug: "npm:^3.0.2" languageName: unknown