From 3281bb8e9f9794b05120d2824d921b5965cf2a88 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 21 Jan 2025 14:17:04 +0200 Subject: [PATCH] feat(geomap): allow dragging --- src/public/app/widgets/type_widgets/geo_map.ts | 18 +++++++++++++----- 1 file changed, 13 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 99450f9ff..67d41a53f 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, LeafletMouseEvent } from "leaflet"; +import type { LatLng, LeafletMouseEvent, Marker } from "leaflet"; import type FNote from "../../entities/fnote.js"; import GeoMapWidget, { type InitCallback, type Leaflet } from "../geo_map.js"; import TypeWidget from "./type_widget.js" @@ -116,9 +116,14 @@ export default class GeoMapTypeWidget extends TypeWidget { } const [ lat, lng ] = latLng.split(",", 2).map((el) => parseFloat(el)); - L.marker(L.latLng(lat, lng)) + L.marker(L.latLng(lat, lng), { + draggable: true + }) .addTo(map) - .bindPopup(childNote.title); + .bindPopup(childNote.title) + .on("moveend", e => { + this.moveMarker(childNote.noteId, (e.target as Marker).getLatLng()); + }); } } @@ -131,12 +136,15 @@ export default class GeoMapTypeWidget extends TypeWidget { return; } - const { noteId } = this.clipboard; - await attributes.setLabel(noteId, LOCATION_ATTRIBUTE, [e.latlng.lat, e.latlng.lng].join(",")); + this.moveMarker(this.clipboard.noteId, e.latlng); this.clipboard = undefined; this.#adjustCursor(); } + async moveMarker(noteId: string, latLng: LatLng) { + await attributes.setLabel(noteId, LOCATION_ATTRIBUTE, [latLng.lat, latLng.lng].join(",")); + } + getData(): any { const map = this.geoMapWidget.map; if (!map) {