Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(geomap): keep a place's icon on the marker made from it
Elian Doran43ab6f33ec66
diff --git a/apps/client/src/widgets/collections/geomap/api.spec.ts b/apps/client/src/widgets/collections/geomap/api.spec.tsindex 03d4cfda44..76f4803ec6 100644--- a/apps/client/src/widgets/collections/geomap/api.spec.ts+++ b/apps/client/src/widgets/collections/geomap/api.spec.ts@@ -59,7 +59,8 @@ describe("geo map api", () => {it("names a note for a searched place as the place is named, and stands it there", async () => {const parent = buildNote({ title: "The map" });- const created = await createNoteForPlace(parent, { name: "Jumbo", lat: 45.796, lng: 24.147 });+ const created = await createNoteForPlace(+ parent, { name: "Jumbo", lat: 45.796, lng: 24.147, icon: "bx bx-cart" });expect(created).toEqual({ noteId: "created" });expect(createNote).toHaveBeenCalledWith(parent.noteId, expect.objectContaining({@@ -69,6 +70,21 @@ describe("geo map api", () => {activate: false,attributes: expect.arrayContaining([{ type: "label", name: "geolocation", value: "45.796,24.147" },+ // The kind of place it is, which is what the panel offered it under (see+ // PlacePanel): a supermarket kept as a marker stays a supermarket.+ { type: "label", name: "iconClass", value: "bx bx-cart" }+ ])+ }));+ });++ it("gives a place of no stated kind the icon a placed marker wears", async () => {+ const parent = buildNote({ title: "The map" });++ // Neither the geocoder nor the tile said what kind of place it is (see placeIcon).+ await createNoteForPlace(parent, { name: "Somewhere", lat: 45.796, lng: 24.147 });++ expect(createNote).toHaveBeenCalledWith(parent.noteId, expect.objectContaining({+ attributes: expect.arrayContaining([{ type: "label", name: "iconClass", value: "bx bx-pin" }])}));diff --git a/apps/client/src/widgets/collections/geomap/api.ts b/apps/client/src/widgets/collections/geomap/api.tsindex f7ad99359f..976b0de0aa 100644--- a/apps/client/src/widgets/collections/geomap/api.ts+++ b/apps/client/src/widgets/collections/geomap/api.ts@@ -113,15 +113,21 @@ export async function createNewNote(parentNote: FNote, e: GeoMouseEvent) {export async function createNoteForPlace(parentNote: FNote, place: PlaceToKeep) {const title = place.unnamed ? undefined : place.name;- return createNoteAt(parentNote, [ place.lat, place.lng ], title);+ return createNoteAt(parentNote, [ place.lat, place.lng ], title, place.icon);}-/** What keeping a place as a marker needs of it: where it stands, and what to call it there. */+/** What keeping a place as a marker needs of it: where it stands, what to call it there, and what+ * kind of place it is. */interface PlaceToKeep {name: string;lat: number;lng: number;unnamed?: boolean;+ /**+ * The boxicons class the place is drawn under, as `GeoSearchResult.icon` gives it. Absent where+ * neither the geocoder nor the tile says what kind of place it is.+ */+ icon?: string;}/**@@ -131,8 +137,13 @@ interface PlaceToKeep {* choosing, which is what leaves the naming to the server: an unnamed note takes the name every* new note takes — the one the tree's + button gives — and a map labelled `#titleTemplate` names* its markers by that instead.+ *+ * `icon` is what the place is already drawn under — a cart for a supermarket, a flag for a country+ * (see placeIcon in osm_icons) — so the marker keeps the icon the panel offered it under. A note+ * dropped by clicking the map has no such place behind it and wears CHILD_NOTE_ICON.*/-async function createNoteAt(parentNote: FNote, [ lat, lng ]: [number, number], title?: string) {+async function createNoteAt(+ parentNote: FNote, [ lat, lng ]: [number, number], title?: string, icon?: string) {const { note } = await note_create.createNote(parentNote.noteId, {title,content: "",@@ -141,7 +152,7 @@ async function createNoteAt(parentNote: FNote, [ lat, lng ]: [number, number], tisProtected: parentNote.isProtected,attributes: [{ type: "label", name: LOCATION_ATTRIBUTE, value: [ lat, lng ].join(",") },- { type: "label", name: "iconClass", value: CHILD_NOTE_ICON }+ { type: "label", name: "iconClass", value: icon ?? CHILD_NOTE_ICON }]});diff --git a/docs/User Guide/User Guide/Collections/Geo Map.md b/docs/User Guide/User Guide/Collections/Geo Map.mdindex 1f1b6267b9..0b54a779e8 100644--- a/docs/User Guide/User Guide/Collections/Geo Map.md+++ b/docs/User Guide/User Guide/Collections/Geo Map.md@@ -92,7 +92,7 @@ A panel then opens with the place's full address and its coordinates: in the top### Keeping a place as a marker-Press _Add as marker_ in that panel to keep the place. A child note is created under the map. It takes the name of the place, and its `#geolocation` attribute is already set. The note opens beside the map, so you can edit it straight away. The temporary pin disappears, because the place is now a marker like any other.+Press _Add as marker_ in that panel to keep the place. A child note is created under the map. It takes the name of the place, as well as the icon, which matches the kind of place it is. Its `#geolocation` attribute is already set. The note opens beside the map, so you can edit it straight away. The temporary pin disappears, because the place is now a marker like any other.The button is not offered on a map that cannot be edited, where the panel can still be read.