|
@@ -1,14 +1,16 @@
|
|
|
import { stageManager } from "./stage-manager";
|
|
|
-
|
|
|
+import { FileParser } from "../parser/file-parser";
|
|
|
class HeaderMenu {
|
|
|
- constructor() {
|
|
|
+ constructor() {}
|
|
|
+ bootstrap() {
|
|
|
$("body").on("click", "#save", this.save.bind(this));
|
|
|
+ $("body").on("click", "#open", this.open.bind(this));
|
|
|
+ $("body").on("change", "#input-file", this.onFileChanged.bind(this));
|
|
|
}
|
|
|
- bootstrap() {}
|
|
|
save() {
|
|
|
const layer = stageManager.getCurrentLayer();
|
|
|
const file = layer.actionManager.save();
|
|
|
- var a = document.createElement("a"),
|
|
|
+ const a = document.createElement("a"),
|
|
|
url = URL.createObjectURL(file);
|
|
|
a.href = url;
|
|
|
a.download = `${layer.name}.geo`;
|
|
@@ -19,5 +21,20 @@ class HeaderMenu {
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
}, 0);
|
|
|
}
|
|
|
+ open() {
|
|
|
+ $("#input-file").click();
|
|
|
+ }
|
|
|
+ onFileChanged() {
|
|
|
+ const files = $("#input-file")[0].files;
|
|
|
+ if (files == undefined || files.length === 0) return;
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onload = function() {
|
|
|
+ const result = reader.result;
|
|
|
+ const parser = new FileParser(result);
|
|
|
+ const map = parser.parse();
|
|
|
+ console.info("map", map);
|
|
|
+ };
|
|
|
+ reader.readAsText(files[0]);
|
|
|
+ }
|
|
|
}
|
|
|
export const headerMenu = new HeaderMenu();
|