summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2020-11-09 16:22:01 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2020-11-20 13:39:20 +0100
commit51a28d0d8bbe49b6be0d576ff1c94824eebd9174 (patch)
tree1e43b3d6d2b10eda864148a7950a20162b7602f0
parent10e3d6874745283b545d3b8029a3e5e184932c5d (diff)
downloadtdde25-51a28d0d8bbe49b6be0d576ff1c94824eebd9174.tar.gz
set color per path in server
-rw-r--r--server.py9
-rw-r--r--templates/index.js10
2 files changed, 13 insertions, 6 deletions
diff --git a/server.py b/server.py
index 6a93018..f86cc60 100644
--- a/server.py
+++ b/server.py
@@ -30,10 +30,13 @@ def shortest_path(body):
target_id = algorithms.get_closest_node_id(nodes, store.Node(-1, body['lat2'], body['lng2']))
path = algorithms.find_shortest_path(nodes, source_id, target_id)
- print(path)
- response = {"path": [(nodes[node].lat, nodes[node].lng) for node in path]}
+ edges = []
+ for i in range(len(path)-1):
+ edges.append({"path": [[nodes[path[i]].lat, nodes[path[i]].lng],
+ [nodes[path[i+1]].lat, nodes[path[i+1]].lng]],
+ "color": "#ff0000"})
- return json.dumps(response)
+ return json.dumps({"edges": edges})
run_server()
diff --git a/templates/index.js b/templates/index.js
index b7b3b58..a7cfd90 100644
--- a/templates/index.js
+++ b/templates/index.js
@@ -27,10 +27,14 @@ async function postShortestPath(event){
body: JSON.stringify(req)
})
- res = await res.json()
- console.log(res.path)
- var poly = L.polyline(res.path).addTo(map)
+ res = await res.json()
+ for (edge of res.edges) {
+ console.log(edge.path)
+ L.polyline(edge.path, {
+ color: edge.color
+ }).addTo(map)
+ }
}
function handleMapClick ({latlng}){