From 92c28fbc54d1aa28208c460fb71333d65efa6ad6 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Fri, 23 Feb 2024 10:28:03 -0500 Subject: [PATCH] made line drawing less of a mess --- BBB_frontend/main.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/BBB_frontend/main.js b/BBB_frontend/main.js index 66608c9..3712be6 100644 --- a/BBB_frontend/main.js +++ b/BBB_frontend/main.js @@ -96,26 +96,29 @@ async function submit(clickEvent){ let from_lon = document.getElementById("from_longitude_input").value; let to_lat = document.getElementById("to_lattitude_input").value; let to_lon = document.getElementById("to_longitude_input").value; + let path = await fetch(`http://localhost:8080/path?time=e&from_lat=${from_lat}&from_lon=${from_lon}&to_lat=${to_lat}&to_lon=${to_lon}`).then(r=>r.json()); + let secs = []; for(let route of path.path){ console.log(route.route_name); secs.push(fetch(`http://localhost:8080/time_to_arrive?service=${route.service}&from=${route.enter_stop_id}&to=${route.exit_stop_id}&route=${route.route_id}`).then(r=>r.json())); - fetch(`http://localhost:8080/route_draw?service=${route.service}&id=${route.route_id}`).then(r=>r.json()).then(v=>{ - return {path:google.maps.geometry.encoding.decodePath(v.poly_line), color:v.color} - }) - .then(o=>{ - //console.log(`"${o.path}"`); - let line = new google.maps.Polyline({ - path:o.path, - strokeColor: o.color, - strokeOpacity: 1.0, - strokeWeight: 3, - }); - line.setMap(map); - window.paths.push(line); - //setTimeout(()=>line.setVisible(false), 5000); - }) + + let route_draw = await fetch(`http://localhost:8080/route_draw?service=${route.service}&id=${route.route_id}`) + .then(r=>r.json()); + + let path=google.maps.geometry.encoding.decodePath(route_draw.poly_line); + + let line = new google.maps.Polyline({ + path, + strokeColor: route_draw.color, + strokeOpacity: 1.0, + strokeWeight: 3, + }); + + line.setMap(map); + window.paths.push(line); +>>>>>>> Stashed changes } Promise.all(secs).then(l=>l.reduce((a,b)=>a+b)).then(v=>alert(`bus ride will take ${display_time(v)}`)); } @@ -131,6 +134,7 @@ function display_time(secs){ } } + async function clear_lines(){ for (let path of window.paths) path.setMap(null); window.paths = [];