diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-17 00:10:40 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2020-11-20 13:40:05 +0100 |
| commit | 82ed960aa540481cecc342716118fb74d349e900 (patch) | |
| tree | 2ca8862d4868369d4fbd7d8db311a9b2f890bee5 /templates/index.js | |
| parent | 10e3d6874745283b545d3b8029a3e5e184932c5d (diff) | |
| download | tdde25-load-file.tar.gz | |
load file with name via formload-file
Diffstat (limited to 'templates/index.js')
| -rw-r--r-- | templates/index.js | 10 |
1 files changed, 10 insertions, 0 deletions
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: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> 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) |
