From 986a1c25be27453fd18c56d74abd62e6168fb33f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 20 Jan 2025 23:53:52 +0200 Subject: [PATCH] feat(geomap): reload markers after adding a new note --- .../app/widgets/type_widgets/geo_map.ts | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/public/app/widgets/type_widgets/geo_map.ts b/src/public/app/widgets/type_widgets/geo_map.ts index 7022b9c20..71580e5de 100644 --- a/src/public/app/widgets/type_widgets/geo_map.ts +++ b/src/public/app/widgets/type_widgets/geo_map.ts @@ -43,6 +43,7 @@ export default class GeoMapTypeWidget extends TypeWidget { private geoMapWidget: GeoMapWidget; private clipboard?: Clipboard; + private L!: Leaflet; static getType() { return "geoMap"; @@ -64,6 +65,7 @@ export default class GeoMapTypeWidget extends TypeWidget { } async #onMapInitialized(L: Leaflet) { + this.L = L; const map = this.geoMapWidget.map; if (!map) { throw new Error("Unable to load map."); @@ -86,7 +88,23 @@ export default class GeoMapTypeWidget extends TypeWidget { map.setView(center, zoom); // Restore markers. + await this.#reloadMarkers(); + + const updateFn = () => this.spacedUpdate.scheduleUpdate(); + map.on("moveend", updateFn); + map.on("zoomend", updateFn); + map.on("click", (e) => this.#onMapClicked(e)); + } + + async #reloadMarkers() { + const map = this.geoMapWidget.map; + + if (!this.note || !map) { + return; + } + const childNotes = await this.note.getChildNotes(); + const L = this.L; for (const childNote of childNotes) { const latLng = childNote.getAttributeValue("label", LOCATION_ATTRIBUTE); if (!latLng) { @@ -98,11 +116,6 @@ export default class GeoMapTypeWidget extends TypeWidget { .addTo(map) .bindPopup(childNote.title); } - - const updateFn = () => this.spacedUpdate.scheduleUpdate(); - map.on("moveend", updateFn); - map.on("zoomend", updateFn); - map.on("click", (e) => this.#onMapClicked(e)); } async #onMapClicked(e: LeafletMouseEvent) { @@ -158,4 +171,11 @@ export default class GeoMapTypeWidget extends TypeWidget { await this.geoMapWidget.refresh(); } + entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { + const attributeRows = loadResults.getAttributeRows(); + if (attributeRows.find((at) => at.name === LOCATION_ATTRIBUTE)) { + this.#reloadMarkers(); + } + } + }