From 90c5be389af6b6ca162d9f16cb8e7133fee9685d Mon Sep 17 00:00:00 2001 From: arielherself Date: Sat, 30 Dec 2023 17:03:06 +0800 Subject: [PATCH 1/4] fix: candidate markers not cleared when clicking the clear button --- PublicProperty.js | 2 +- api/click.js | 5 +++++ src/UMap.js | 15 ++++++--------- tools/ShortestPath.js | 4 ---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/PublicProperty.js b/PublicProperty.js index 8aa8f6a..9d2cee6 100644 --- a/PublicProperty.js +++ b/PublicProperty.js @@ -1,6 +1,6 @@ // no dependencies -export const __DEBUG__ = 0; +export const __DEBUG__ = 1; export const __APP_VERSION__ = 'v0.3.2-beta'; export const __APP_INTRO__ = ` diff --git a/api/click.js b/api/click.js index 812dd26..dd32828 100644 --- a/api/click.js +++ b/api/click.js @@ -68,6 +68,7 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => { const ch_dict = {}; const ch_dict_bench = {}; let f = 1; + // let time = 0; for (const t in ways) { // if (t === ways[aff[actual_start_node_id]]) sill('yes'); const [l, n] = get_row(ways, t); @@ -87,6 +88,7 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => { // ch_dict_bench[prev] = [[curr, distance]]; // } // } + // const start_time = performance.now(); let prev = ''; let distance = 0; for (let i = 0; i < n; ++i) { @@ -111,7 +113,10 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => { distance = 0; } } + // const end_time = performance.now(); + // time += end_time - start_time; } + // sill(`Preprocessing time: ${time}`); // const clean_nodes = {}; // Object.keys(nodes).forEach((node_id) => { // if (ch_dict[node_id]) clean_nodes[node_id] = nodes[node_id]; diff --git a/src/UMap.js b/src/UMap.js index a3377cc..61145de 100644 --- a/src/UMap.js +++ b/src/UMap.js @@ -39,7 +39,7 @@ class Markers extends Component { addMarker(lat, lng) { this.setState((prev) => ({ markers: [...prev.markers, [lat, lng]], - candMarkers: prev.candMarkers, + candMarkers: [], mksEmpty: false, candEmpty: prev.candEmpty, polylines: prev.polylines, @@ -115,12 +115,7 @@ function MapClickHandler({mks,focusUpdater,locator,locker}) { sill(`Clicking on ${lat} ${lng}`); mks.current.addMarker(lat, lng); post('POST', 'click', mks.current.state.markers.slice(-2)).then((response) => { - // TODO: real functionality const pl = JSON.parse(response.multipolyline); - // DEBUG - // response.__debug_pts.forEach(({lat,lon})=>{ - // mks.current.addCandMarker(lat,lon); - // }); sill(`pl = ${JSON.stringify(pl)}`); if (pl.length > 1) mks.current.flushPolylines(pl, false); focusUpdater([lat,lng]); @@ -165,7 +160,6 @@ const LocationSearch = ({mks, focus, nb}) => { setLoading(true); setQuery(v); try { - // setSuggestedLocations([]); if (v.trim() === '') { setLoading(false); return; @@ -177,7 +171,6 @@ const LocationSearch = ({mks, focus, nb}) => { if (response.ok) { response.json().then((data) => { if (data.length > 0) { - // const {lat, lon} = data[0]; mks.current.clearCandMarkers(); const res = []; data.forEach((v, i, a) => { @@ -231,6 +224,10 @@ export default function UMap() { sf(locatedFocus); setLocated(true); }; + const clr = () => { + markersRef.current.clearMarkers(); + markersRef.current.clearCandMarkers(); + }; const ViewportChange = () => { const map = useMapEvents({ dragend: (e) => { @@ -259,7 +256,7 @@ export default function UMap() { - + diff --git a/tools/ShortestPath.js b/tools/ShortestPath.js index b28dc39..807739e 100644 --- a/tools/ShortestPath.js +++ b/tools/ShortestPath.js @@ -125,8 +125,6 @@ function __obvious_dijkstra(nodes, ways, loc, ch, count, aff, u, p) { const prev = curr; curr = fa[curr]; if (vis.has(curr)) { - // sill(`Cycle at ${curr}`); - // sill(res); break; } vis.set(curr,true); @@ -216,8 +214,6 @@ function __obvious_a_star(nodes, ways, loc, ch, count, aff, u, p, adaptive = fal const prev = curr; curr = fa[curr]; if (vis.has(curr)) { - // sill(`Cycle at ${curr}`); - // sill(res); break; } vis.set(curr,true); From de5e4cc4d215ce50af63f8b833793b0c175f572e Mon Sep 17 00:00:00 2001 From: arielherself Date: Sat, 30 Dec 2023 17:03:32 +0800 Subject: [PATCH 2/4] chore: bump version --- PublicProperty.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PublicProperty.js b/PublicProperty.js index 9d2cee6..95e5120 100644 --- a/PublicProperty.js +++ b/PublicProperty.js @@ -1,7 +1,7 @@ // no dependencies export const __DEBUG__ = 1; -export const __APP_VERSION__ = 'v0.3.2-beta'; +export const __APP_VERSION__ = 'v0.3.3-beta'; export const __APP_INTRO__ = ` Algorithm improvement.
From 14500262700e6ae3b58775ca21d045077a1ca2f7 Mon Sep 17 00:00:00 2001 From: arielherself Date: Sat, 30 Dec 2023 17:11:16 +0800 Subject: [PATCH 3/4] feat: discard route if there's only one point --- api/click.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/click.js b/api/click.js index dd32828..364ddc1 100644 --- a/api/click.js +++ b/api/click.js @@ -151,8 +151,7 @@ export default function handler(req, res) { sill(`Requesting ${request_uri}`); const fetch_debug_response = fetch(request_uri).then((response) => { return response.json(); - }); - fetch_debug_response.then((debug_response) => { + }).then((debug_response) => { // sill(debug_response); let ps = {}; let ws = {}; @@ -163,7 +162,8 @@ export default function handler(req, res) { ws[it.id] = it.nodes; } }); - const path_found = shortest_path(ps, ws, pts[0], pts[pts.length - 1]); + sill(pts.length); + const path_found = pts.length < 2 ? [] : shortest_path(ps, ws, pts[0], pts[pts.length - 1]); res.status(200).json({ log: `Method: click\nArgs: ${pts}\nStatus: requested "${request_uri}", got response ${JSON.stringify(debug_response.elements)}`, multipolyline: JSON.stringify(path_found), From 8a589200e22154306c52af08081e2b00312e40e8 Mon Sep 17 00:00:00 2001 From: arielherself Date: Sat, 30 Dec 2023 17:11:33 +0800 Subject: [PATCH 4/4] chore: bump version --- PublicProperty.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PublicProperty.js b/PublicProperty.js index 95e5120..a83b2f7 100644 --- a/PublicProperty.js +++ b/PublicProperty.js @@ -1,7 +1,7 @@ // no dependencies -export const __DEBUG__ = 1; -export const __APP_VERSION__ = 'v0.3.3-beta'; +export const __DEBUG__ = 0; +export const __APP_VERSION__ = 'v0.3.4-beta'; export const __APP_INTRO__ = ` Algorithm improvement.