Initial implementation (#4)

This commit is contained in:
Matthew Ryan Dillon 2020-11-12 16:09:28 -07:00 committed by GitHub
parent a78b14ae33
commit ec2651207c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 281 additions and 25 deletions

View file

@ -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>

View file

@ -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);
}