Skip to content

Commit 2c19ac2

Browse files
authored
Merge pull request #3 from arielherself/dev
v0.3.4-beta
2 parents aaad1cc + 8a58920 commit 2c19ac2

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

PublicProperty.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// no dependencies
22

33
export const __DEBUG__ = 0;
4-
export const __APP_VERSION__ = 'v0.3.2-beta';
4+
export const __APP_VERSION__ = 'v0.3.4-beta';
55

66
export const __APP_INTRO__ = `
77
<b>Algorithm improvement.</b><br>

api/click.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => {
6868
const ch_dict = {};
6969
const ch_dict_bench = {};
7070
let f = 1;
71+
// let time = 0;
7172
for (const t in ways) {
7273
// if (t === ways[aff[actual_start_node_id]]) sill('yes');
7374
const [l, n] = get_row(ways, t);
@@ -87,6 +88,7 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => {
8788
// ch_dict_bench[prev] = [[curr, distance]];
8889
// }
8990
// }
91+
// const start_time = performance.now();
9092
let prev = '';
9193
let distance = 0;
9294
for (let i = 0; i < n; ++i) {
@@ -111,7 +113,10 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => {
111113
distance = 0;
112114
}
113115
}
116+
// const end_time = performance.now();
117+
// time += end_time - start_time;
114118
}
119+
// sill(`Preprocessing time: ${time}`);
115120
// const clean_nodes = {};
116121
// Object.keys(nodes).forEach((node_id) => {
117122
// if (ch_dict[node_id]) clean_nodes[node_id] = nodes[node_id];
@@ -146,8 +151,7 @@ export default function handler(req, res) {
146151
sill(`Requesting ${request_uri}`);
147152
const fetch_debug_response = fetch(request_uri).then((response) => {
148153
return response.json();
149-
});
150-
fetch_debug_response.then((debug_response) => {
154+
}).then((debug_response) => {
151155
// sill(debug_response);
152156
let ps = {};
153157
let ws = {};
@@ -158,7 +162,8 @@ export default function handler(req, res) {
158162
ws[it.id] = it.nodes;
159163
}
160164
});
161-
const path_found = shortest_path(ps, ws, pts[0], pts[pts.length - 1]);
165+
sill(pts.length);
166+
const path_found = pts.length < 2 ? [] : shortest_path(ps, ws, pts[0], pts[pts.length - 1]);
162167
res.status(200).json({
163168
log: `Method: click\nArgs: ${pts}\nStatus: requested "${request_uri}", got response ${JSON.stringify(debug_response.elements)}`,
164169
multipolyline: JSON.stringify(path_found),

src/UMap.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Markers extends Component {
3939
addMarker(lat, lng) {
4040
this.setState((prev) => ({
4141
markers: [...prev.markers, [lat, lng]],
42-
candMarkers: prev.candMarkers,
42+
candMarkers: [],
4343
mksEmpty: false,
4444
candEmpty: prev.candEmpty,
4545
polylines: prev.polylines,
@@ -115,12 +115,7 @@ function MapClickHandler({mks,focusUpdater,locator,locker}) {
115115
sill(`Clicking on ${lat} ${lng}`);
116116
mks.current.addMarker(lat, lng);
117117
post('POST', 'click', mks.current.state.markers.slice(-2)).then((response) => {
118-
// TODO: real functionality
119118
const pl = JSON.parse(response.multipolyline);
120-
// DEBUG
121-
// response.__debug_pts.forEach(({lat,lon})=>{
122-
// mks.current.addCandMarker(lat,lon);
123-
// });
124119
sill(`pl = ${JSON.stringify(pl)}`);
125120
if (pl.length > 1) mks.current.flushPolylines(pl, false);
126121
focusUpdater([lat,lng]);
@@ -165,7 +160,6 @@ const LocationSearch = ({mks, focus, nb}) => {
165160
setLoading(true);
166161
setQuery(v);
167162
try {
168-
// setSuggestedLocations([]);
169163
if (v.trim() === '') {
170164
setLoading(false);
171165
return;
@@ -177,7 +171,6 @@ const LocationSearch = ({mks, focus, nb}) => {
177171
if (response.ok) {
178172
response.json().then((data) => {
179173
if (data.length > 0) {
180-
// const {lat, lon} = data[0];
181174
mks.current.clearCandMarkers();
182175
const res = [];
183176
data.forEach((v, i, a) => {
@@ -231,6 +224,10 @@ export default function UMap() {
231224
sf(locatedFocus);
232225
setLocated(true);
233226
};
227+
const clr = () => {
228+
markersRef.current.clearMarkers();
229+
markersRef.current.clearCandMarkers();
230+
};
234231
const ViewportChange = () => {
235232
const map = useMapEvents({
236233
dragend: (e) => {
@@ -259,7 +256,7 @@ export default function UMap() {
259256
<ViewportChange/>
260257
</MapContainer>
261258
<Sheet sx={{position: 'absolute', top: '20px', right: '10vw', zIndex: 'modal'}}>
262-
<SimulateClick isLocated={located} relocator={relo} isMarkersEmpty={markersRef.current ? markersRef.current.state.mksEmpty : true} clearMarkers={markersRef.current ? markersRef.current.clearMarkers : null}/>
259+
<SimulateClick isLocated={located} relocator={relo} isMarkersEmpty={markersRef.current ? markersRef.current.state.mksEmpty : true} clearMarkers={clr}/>
263260
<LocationSearch nb={nearbyName} mks={markersRef} focus={focus}/>
264261
</Sheet>
265262
</Sheet>

tools/ShortestPath.js

-4
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ function __obvious_dijkstra(nodes, ways, loc, ch, count, aff, u, p) {
125125
const prev = curr;
126126
curr = fa[curr];
127127
if (vis.has(curr)) {
128-
// sill(`Cycle at ${curr}`);
129-
// sill(res);
130128
break;
131129
}
132130
vis.set(curr,true);
@@ -216,8 +214,6 @@ function __obvious_a_star(nodes, ways, loc, ch, count, aff, u, p, adaptive = fal
216214
const prev = curr;
217215
curr = fa[curr];
218216
if (vis.has(curr)) {
219-
// sill(`Cycle at ${curr}`);
220-
// sill(res);
221217
break;
222218
}
223219
vis.set(curr,true);

0 commit comments

Comments
 (0)