From a3f257f3c583d95879f9f1de14b40c5c72090ede Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 20 Jan 2025 23:14:31 +0200 Subject: [PATCH] feat(geomap): set location after creating a note --- src/public/app/widgets/type_widgets/geo_map.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/public/app/widgets/type_widgets/geo_map.ts b/src/public/app/widgets/type_widgets/geo_map.ts index bd41e4878..740f9838e 100644 --- a/src/public/app/widgets/type_widgets/geo_map.ts +++ b/src/public/app/widgets/type_widgets/geo_map.ts @@ -1,4 +1,4 @@ -import type { LatLng } from "leaflet"; +import type { LatLng, LeafletMouseEvent } from "leaflet"; import type FNote from "../../entities/fnote.js"; import GeoMapWidget from "../geo_map.js"; import TypeWidget from "./type_widget.js" @@ -7,6 +7,7 @@ import toastService from "../../services/toast.js"; import dialogService from "../../services/dialog.js"; import type { EventData } from "../../components/app_context.js"; import { t } from "../../services/i18n.js"; +import attributes from "../../services/attributes.js"; const TPL = `\
@@ -17,6 +18,8 @@ const TPL = `\
`; +const LOCATION_ATTRIBUTE = "latLng"; + interface MapData { view?: { center?: LatLng | [ number, number ]; @@ -80,6 +83,16 @@ export default class GeoMapTypeWidget extends TypeWidget { const updateFn = () => this.spacedUpdate.scheduleUpdate(); map.on("moveend", updateFn); map.on("zoomend", updateFn); + map.on("click", (e) => this.#onMapClicked(e)); + } + + async #onMapClicked(e: LeafletMouseEvent) { + if (!this.clipboard) { + return; + } + + const { noteId } = this.clipboard; + await attributes.setLabel(noteId, LOCATION_ATTRIBUTE, [e.latlng.lat, e.latlng.lng].join(",")); } getData(): any {