header-menu.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { stageManager } from "./stage-manager";
  2. import { FileParser } from "../parser/file-parser";
  3. class HeaderMenu {
  4. constructor() {}
  5. bootstrap() {
  6. $("body").on("click", "#save", this.save.bind(this));
  7. $("body").on("click", "#open", this.open.bind(this));
  8. $("body").on("change", "#input-file", this.onFileChanged.bind(this));
  9. }
  10. save() {
  11. const layer = stageManager.getCurrentLayer();
  12. const file = layer.actionManager.save();
  13. const a = document.createElement("a"),
  14. url = URL.createObjectURL(file);
  15. a.href = url;
  16. a.download = `${layer.name}.geo`;
  17. document.body.appendChild(a);
  18. a.click();
  19. setTimeout(function() {
  20. document.body.removeChild(a);
  21. window.URL.revokeObjectURL(url);
  22. }, 0);
  23. }
  24. open() {
  25. $("#input-file").click();
  26. }
  27. onFileChanged() {
  28. const files = $("#input-file")[0].files;
  29. if (files == undefined || files.length === 0) return;
  30. const reader = new FileReader();
  31. reader.onload = function() {
  32. const result = reader.result;
  33. const parser = new FileParser(result);
  34. const map = parser.parse();
  35. console.info("map", map);
  36. };
  37. reader.readAsText(files[0]);
  38. }
  39. }
  40. export const headerMenu = new HeaderMenu();