commit
2c19ac20de
|
@ -1,7 +1,7 @@
|
||||||
// no dependencies
|
// no dependencies
|
||||||
|
|
||||||
export const __DEBUG__ = 0;
|
export const __DEBUG__ = 0;
|
||||||
export const __APP_VERSION__ = 'v0.3.2-beta';
|
export const __APP_VERSION__ = 'v0.3.4-beta';
|
||||||
|
|
||||||
export const __APP_INTRO__ = `
|
export const __APP_INTRO__ = `
|
||||||
<b>Algorithm improvement.</b><br>
|
<b>Algorithm improvement.</b><br>
|
||||||
|
|
11
api/click.js
11
api/click.js
|
@ -68,6 +68,7 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => {
|
||||||
const ch_dict = {};
|
const ch_dict = {};
|
||||||
const ch_dict_bench = {};
|
const ch_dict_bench = {};
|
||||||
let f = 1;
|
let f = 1;
|
||||||
|
// let time = 0;
|
||||||
for (const t in ways) {
|
for (const t in ways) {
|
||||||
// if (t === ways[aff[actual_start_node_id]]) sill('yes');
|
// if (t === ways[aff[actual_start_node_id]]) sill('yes');
|
||||||
const [l, n] = get_row(ways, t);
|
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]];
|
// ch_dict_bench[prev] = [[curr, distance]];
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
// const start_time = performance.now();
|
||||||
let prev = '';
|
let prev = '';
|
||||||
let distance = 0;
|
let distance = 0;
|
||||||
for (let i = 0; i < n; ++i) {
|
for (let i = 0; i < n; ++i) {
|
||||||
|
@ -111,7 +113,10 @@ const shortest_path = noexcept((nodes, ways, start_point, end_point) => {
|
||||||
distance = 0;
|
distance = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// const end_time = performance.now();
|
||||||
|
// time += end_time - start_time;
|
||||||
}
|
}
|
||||||
|
// sill(`Preprocessing time: ${time}`);
|
||||||
// const clean_nodes = {};
|
// const clean_nodes = {};
|
||||||
// Object.keys(nodes).forEach((node_id) => {
|
// Object.keys(nodes).forEach((node_id) => {
|
||||||
// if (ch_dict[node_id]) clean_nodes[node_id] = nodes[node_id];
|
// if (ch_dict[node_id]) clean_nodes[node_id] = nodes[node_id];
|
||||||
|
@ -146,8 +151,7 @@ export default function handler(req, res) {
|
||||||
sill(`Requesting ${request_uri}`);
|
sill(`Requesting ${request_uri}`);
|
||||||
const fetch_debug_response = fetch(request_uri).then((response) => {
|
const fetch_debug_response = fetch(request_uri).then((response) => {
|
||||||
return response.json();
|
return response.json();
|
||||||
});
|
}).then((debug_response) => {
|
||||||
fetch_debug_response.then((debug_response) => {
|
|
||||||
// sill(debug_response);
|
// sill(debug_response);
|
||||||
let ps = {};
|
let ps = {};
|
||||||
let ws = {};
|
let ws = {};
|
||||||
|
@ -158,7 +162,8 @@ export default function handler(req, res) {
|
||||||
ws[it.id] = it.nodes;
|
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({
|
res.status(200).json({
|
||||||
log: `Method: click\nArgs: ${pts}\nStatus: requested "${request_uri}", got response ${JSON.stringify(debug_response.elements)}`,
|
log: `Method: click\nArgs: ${pts}\nStatus: requested "${request_uri}", got response ${JSON.stringify(debug_response.elements)}`,
|
||||||
multipolyline: JSON.stringify(path_found),
|
multipolyline: JSON.stringify(path_found),
|
||||||
|
|
15
src/UMap.js
15
src/UMap.js
|
@ -39,7 +39,7 @@ class Markers extends Component {
|
||||||
addMarker(lat, lng) {
|
addMarker(lat, lng) {
|
||||||
this.setState((prev) => ({
|
this.setState((prev) => ({
|
||||||
markers: [...prev.markers, [lat, lng]],
|
markers: [...prev.markers, [lat, lng]],
|
||||||
candMarkers: prev.candMarkers,
|
candMarkers: [],
|
||||||
mksEmpty: false,
|
mksEmpty: false,
|
||||||
candEmpty: prev.candEmpty,
|
candEmpty: prev.candEmpty,
|
||||||
polylines: prev.polylines,
|
polylines: prev.polylines,
|
||||||
|
@ -115,12 +115,7 @@ function MapClickHandler({mks,focusUpdater,locator,locker}) {
|
||||||
sill(`Clicking on ${lat} ${lng}`);
|
sill(`Clicking on ${lat} ${lng}`);
|
||||||
mks.current.addMarker(lat, lng);
|
mks.current.addMarker(lat, lng);
|
||||||
post('POST', 'click', mks.current.state.markers.slice(-2)).then((response) => {
|
post('POST', 'click', mks.current.state.markers.slice(-2)).then((response) => {
|
||||||
// TODO: real functionality
|
|
||||||
const pl = JSON.parse(response.multipolyline);
|
const pl = JSON.parse(response.multipolyline);
|
||||||
// DEBUG
|
|
||||||
// response.__debug_pts.forEach(({lat,lon})=>{
|
|
||||||
// mks.current.addCandMarker(lat,lon);
|
|
||||||
// });
|
|
||||||
sill(`pl = ${JSON.stringify(pl)}`);
|
sill(`pl = ${JSON.stringify(pl)}`);
|
||||||
if (pl.length > 1) mks.current.flushPolylines(pl, false);
|
if (pl.length > 1) mks.current.flushPolylines(pl, false);
|
||||||
focusUpdater([lat,lng]);
|
focusUpdater([lat,lng]);
|
||||||
|
@ -165,7 +160,6 @@ const LocationSearch = ({mks, focus, nb}) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setQuery(v);
|
setQuery(v);
|
||||||
try {
|
try {
|
||||||
// setSuggestedLocations([]);
|
|
||||||
if (v.trim() === '') {
|
if (v.trim() === '') {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
|
@ -177,7 +171,6 @@ const LocationSearch = ({mks, focus, nb}) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
response.json().then((data) => {
|
response.json().then((data) => {
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
// const {lat, lon} = data[0];
|
|
||||||
mks.current.clearCandMarkers();
|
mks.current.clearCandMarkers();
|
||||||
const res = [];
|
const res = [];
|
||||||
data.forEach((v, i, a) => {
|
data.forEach((v, i, a) => {
|
||||||
|
@ -231,6 +224,10 @@ export default function UMap() {
|
||||||
sf(locatedFocus);
|
sf(locatedFocus);
|
||||||
setLocated(true);
|
setLocated(true);
|
||||||
};
|
};
|
||||||
|
const clr = () => {
|
||||||
|
markersRef.current.clearMarkers();
|
||||||
|
markersRef.current.clearCandMarkers();
|
||||||
|
};
|
||||||
const ViewportChange = () => {
|
const ViewportChange = () => {
|
||||||
const map = useMapEvents({
|
const map = useMapEvents({
|
||||||
dragend: (e) => {
|
dragend: (e) => {
|
||||||
|
@ -259,7 +256,7 @@ export default function UMap() {
|
||||||
<ViewportChange/>
|
<ViewportChange/>
|
||||||
</MapContainer>
|
</MapContainer>
|
||||||
<Sheet sx={{position: 'absolute', top: '20px', right: '10vw', zIndex: 'modal'}}>
|
<Sheet sx={{position: 'absolute', top: '20px', right: '10vw', zIndex: 'modal'}}>
|
||||||
<SimulateClick isLocated={located} relocator={relo} isMarkersEmpty={markersRef.current ? markersRef.current.state.mksEmpty : true} clearMarkers={markersRef.current ? markersRef.current.clearMarkers : null}/>
|
<SimulateClick isLocated={located} relocator={relo} isMarkersEmpty={markersRef.current ? markersRef.current.state.mksEmpty : true} clearMarkers={clr}/>
|
||||||
<LocationSearch nb={nearbyName} mks={markersRef} focus={focus}/>
|
<LocationSearch nb={nearbyName} mks={markersRef} focus={focus}/>
|
||||||
</Sheet>
|
</Sheet>
|
||||||
</Sheet>
|
</Sheet>
|
||||||
|
|
|
@ -125,8 +125,6 @@ function __obvious_dijkstra(nodes, ways, loc, ch, count, aff, u, p) {
|
||||||
const prev = curr;
|
const prev = curr;
|
||||||
curr = fa[curr];
|
curr = fa[curr];
|
||||||
if (vis.has(curr)) {
|
if (vis.has(curr)) {
|
||||||
// sill(`Cycle at ${curr}`);
|
|
||||||
// sill(res);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vis.set(curr,true);
|
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;
|
const prev = curr;
|
||||||
curr = fa[curr];
|
curr = fa[curr];
|
||||||
if (vis.has(curr)) {
|
if (vis.has(curr)) {
|
||||||
// sill(`Cycle at ${curr}`);
|
|
||||||
// sill(res);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vis.set(curr,true);
|
vis.set(curr,true);
|
||||||
|
|
Loading…
Reference in New Issue