diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-19 16:19:42 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-20 13:39:05 +0100 |
| commit | 7f6aae6eb8f07b71c32311347ddbce92a3874c7d (patch) | |
| tree | 35dc7367d2d5d1b501950c3efdc7589187395180 | |
| parent | cdcdf5de8846b0fe1cb91cc0c6ec41f5842c7c98 (diff) | |
| download | tdde25-7f6aae6eb8f07b71c32311347ddbce92a3874c7d.tar.gz | |
show unconnected nodes on map
| -rw-r--r-- | server.py | 10 | ||||
| -rw-r--r-- | store.py | 9 | ||||
| -rw-r--r-- | templates/index.js | 11 |
3 files changed, 26 insertions, 4 deletions
@@ -11,7 +11,9 @@ nodes = None @get('/') def index(): global nodes - nodes = store.extract_osm_nodes("university.osm") + global unconnected_nodes + nodes, unconnected_nodes = store.extract_osm_nodes("university.osm") + return read_html('templates/index.html') @@ -23,6 +25,12 @@ def show_area(): return json.dumps(rect) +@get('/show-unconnected-nodes') +def show_unconnected_nodes(): + print(f"Showing {len(unconnected_nodes)} unconnected nodes") + return json.dumps({node.id: node.coord_tuple() for node in unconnected_nodes}) + + @post('/shortest-path') def shortest_path(body): body = json.loads(body) @@ -79,14 +79,21 @@ def extract_osm_nodes(f_name): # find the largest disjoin tree best_size = 0 best_tree = None + best_root = None for root in forest: tree = forest[root] size = len(tree) if size > best_size: best_size = size best_tree = tree + best_root = root - return best_tree + unconnected_nodes = [] + for _, node in nodes.items(): + if node.find_root().id != best_root: + unconnected_nodes.append(node) + + return best_tree, unconnected_nodes def select_nodes_in_rectangle(nodes, min_lat, max_lat, min_long, max_long): diff --git a/templates/index.js b/templates/index.js index b7b3b58..3edbd26 100644 --- a/templates/index.js +++ b/templates/index.js @@ -49,7 +49,6 @@ map.on('click', handleMapClick) function showMarker(){ var marker = L.marker([58.3984, 15.5733]).addTo(map) } - showMarker() async function showMarkers() { @@ -59,5 +58,13 @@ async function showMarkers() { var marker = L.marker(res[key]).addTo(map) } } - showMarkers() + +async function showUnconnectedMarkers() { + res = await fetch('/show-unconnected-nodes'); + res = await res.json(); + for (let key in res) { + var marker = L.marker(res[key]).addTo(map) + } +} +showUnconnectedMarkers() |
