Initial implementation (#4)
This commit is contained in:
parent
a78b14ae33
commit
ec2651207c
6 changed files with 281 additions and 25 deletions
|
@ -6,6 +6,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
|
||||
<input id="input" type="file" multiple>
|
||||
<script src="./bootstrap.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
28
www/index.js
28
www/index.js
|
@ -1,3 +1,27 @@
|
|||
import * as wasm from "gpx-web-utils";
|
||||
import * as gpx from "gpx-web-utils";
|
||||
|
||||
wasm.greet();
|
||||
const inputElement = document.getElementById("input");
|
||||
|
||||
inputElement.addEventListener("change", readFiles, false);
|
||||
|
||||
function readFiles() {
|
||||
if (inputElement.files.length < 2) { alert("open two or more files"); return; }
|
||||
|
||||
const files = Array.from(inputElement.files);
|
||||
const promises = files.map(f => f.text());
|
||||
|
||||
Promise.all(promises).then(gpxes => {
|
||||
const merged = gpx.merge(gpxes);
|
||||
writeOutput(merged);
|
||||
inputElement.value = "";
|
||||
});
|
||||
}
|
||||
|
||||
function writeOutput(file) {
|
||||
const blob = new Blob([file], {type: "text/gpx"});
|
||||
const a = document.createElement("a");
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = "merged.gpx";
|
||||
a.click();
|
||||
URL.revokeObjectURL(a.href);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue