From 82ed960aa540481cecc342716118fb74d349e900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 17 Nov 2020 00:10:40 +0100 Subject: load file with name via form --- server.py | 11 +++++++++-- templates/index.html | 17 ++++++++++++++--- templates/index.js | 10 ++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/server.py b/server.py index 6a93018..03d2726 100644 --- a/server.py +++ b/server.py @@ -10,8 +10,6 @@ nodes = None @get('/') def index(): - global nodes - nodes = store.extract_osm_nodes("university.osm") return read_html('templates/index.html') @@ -36,4 +34,13 @@ def shortest_path(body): return json.dumps(response) +@post("/load-file") +def load_osm(body): + global nodes + body = json.loads(body) + print(body) + nodes = store.extract_osm_nodes(body["filename"]) + return "" + + run_server() diff --git a/templates/index.html b/templates/index.html index b29f84f..614a0ac 100644 --- a/templates/index.html +++ b/templates/index.html @@ -43,8 +43,19 @@ - + +
+ +
+
+
+ + +
+
+ +
+
{{ templates/index.js }} - - \ No newline at end of file + diff --git a/templates/index.js b/templates/index.js index b7b3b58..d4cc5a5 100644 --- a/templates/index.js +++ b/templates/index.js @@ -3,6 +3,7 @@ const form = document.querySelector('#path-form') const markerIsStart = document.querySelector("#marker-point-start") const markerIsEnd = document.querySelector("#marker-point-end") form.addEventListener('submit', postShortestPath, false) +document.querySelector("#osm-file-form").addEventListener('submit', loadFile, false) L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' @@ -33,6 +34,15 @@ async function postShortestPath(event){ } +async function loadFile(event) { + event.preventDefault() + await fetch("/load-file", { + method: "POST", + credentials: "same-origin", + body: JSON.stringify({"filename": document.querySelector("#filename").value}) + }) +} + function handleMapClick ({latlng}){ var {lat, lng} = latlng var marker = L.marker([lat, lng]).addTo(map) -- cgit v1.2.1