diff --git a/.gitignore b/.gitignore index f06235c..1a2baae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -node_modules -dist +node_modules/ +dist/ +npm_output.log \ No newline at end of file diff --git a/index.html b/index.html index cc95fbf..bc94d0d 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,7 @@
+
+ + Export as GeoJSON + + `; + } + + connectedCallback() { + const button = this.shadowRoot!.querySelector("button"); + const dialog = this.shadowRoot!.querySelector("dialog"); + const exportLink = this.shadowRoot!.querySelector("#export-geojson"); + + button?.addEventListener("click", () => { + if (dialog?.open) { + dialog.close(); + } else { + dialog?.showModal(); + } + }); + + exportLink?.addEventListener("click", (e) => { + e.preventDefault(); + this.exportAsGeoJSON(); + dialog?.close(); + }); + } + + async exportAsGeoJSON() { + const notes = await db.notes.toArray(); + const features = notes.map((note) => + point([note.lon, note.lat], { + timestamp: note.time, + text: note.text, + }) + ); + const featureCollectionObject = featureCollection(features); + + const dataStr = + "data:text/json;charset=utf-8," + + encodeURIComponent(JSON.stringify(featureCollectionObject)); + const downloadAnchorNode = document.createElement("a"); + downloadAnchorNode.setAttribute("href", dataStr); + downloadAnchorNode.setAttribute("download", "cycloops-notes.geojson"); + document.body.appendChild(downloadAnchorNode); // required for firefox + downloadAnchorNode.click(); + downloadAnchorNode.remove(); + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index e8eb541..739b5ee 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,9 @@ import "./style.css"; import { CycloopsForm } from "./components/form"; import { CycloopsList } from "./components/list"; import { CycloopsMap } from "./components/map"; +import { CycloopsMenu } from "./components/menu"; customElements.define("cycloops-form", CycloopsForm, { extends: "form" }); customElements.define("cycloops-list", CycloopsList, { extends: "ol" }); customElements.define("cycloops-map", CycloopsMap, { extends: "div" }); +customElements.define("cycloops-menu", CycloopsMenu, { extends: "div" });