Skip to content

Build your personal knowledge base with Trilium Notes

feat(mindmap): save view center coordinates

Elian Doran5cefd4f50ad4
diff --git a/src/public/app/widgets/geo_map.ts b/src/public/app/widgets/geo_map.ts
index 834be61390..990b34b6c7 100644
--- a/src/public/app/widgets/geo_map.ts
+++ b/src/public/app/widgets/geo_map.ts
@@ -1,3 +1,4 @@
+import type { Map } from "leaflet";
import library_loader from "../services/library_loader.js";
import NoteContextAwareWidget from "./note_context_aware_widget.js";
@@ -17,8 +18,12 @@ const TPL = `\
export default class GeoMapWidget extends NoteContextAwareWidget {
- constructor(widgetMode: "type") {
+ map?: Map;
+ private initCallback?: () => void;
+
+ constructor(widgetMode: "type", initCallback?: () => void) {
super();
+ this.initCallback = initCallback;
}
doRender() {
@@ -35,6 +40,10 @@ export default class GeoMapWidget extends NoteContextAwareWidget {
});
map.setView([51.505, -0.09], 13);
+ this.map = map;
+ if (this.initCallback) {
+ this.initCallback();
+ }
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
diff --git a/src/public/app/widgets/type_widgets/geo_map.ts b/src/public/app/widgets/type_widgets/geo_map.ts
index f52a7a8e09..f619b01c8f 100644
--- a/src/public/app/widgets/type_widgets/geo_map.ts
+++ b/src/public/app/widgets/type_widgets/geo_map.ts
@@ -15,7 +15,8 @@ export default class GeoMapTypeWidget extends TypeWidget {
constructor() {
super();
- this.geoMapWidget = new GeoMapWidget("type");
+ this.geoMapWidget = new GeoMapWidget("type", () => this.#onMapInitialized());
+
this.child(this.geoMapWidget);
}
@@ -26,6 +27,27 @@ export default class GeoMapTypeWidget extends TypeWidget {
super.doRender();
}
+ #onMapInitialized() {
+ this.geoMapWidget.map?.on("moveend", () => this.spacedUpdate.scheduleUpdate());
+ }
+
+ getData(): any {
+ const map = this.geoMapWidget.map;
+ if (!map) {
+ return;
+ }
+
+ const data = {
+ view: {
+ center: map.getBounds().getCenter()
+ }
+ };
+
+ return {
+ content: JSON.stringify(data)
+ };
+ }
+
async doRefresh(note: FNote) {
await this.geoMapWidget.refresh();
}