Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): name a note kept from a point as a placed marker is named

Elian Doran70355472a4e4
diff --git a/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx b/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx
index 0dbed7fec8..bcbf4c7c9f 100644
--- a/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/SearchBox.spec.tsx
@@ -261,7 +261,14 @@ describe("geo map SearchBox", () => {
// Pinned and offered for keeping as a searched place is, and shown as closely as it was
// meant rather than at the level a place of unsaid extent gets.
- expect(pickedPlace()).toMatchObject({ name: "45.9432, 24.9668", lat: 45.9432, lng: 24.9668 });
+ expect(pickedPlace()).toMatchObject({
+ name: "45.9432, 24.9668",
+ lat: 45.9432,
+ lng: 24.9668,
+ // Named by where it stands and nothing else, so a note kept from it is named as a
+ // placed marker is rather than after its own coordinates (see createNoteForPlace).
+ unnamed: true
+ });
expect(map.flyTo).toHaveBeenCalledWith({ center: [ 24.9668, 45.9432 ], zoom: 16 });
});
diff --git a/apps/client/src/widgets/collections/geomap/SearchBox.tsx b/apps/client/src/widgets/collections/geomap/SearchBox.tsx
index 4927f972e8..1bd8573f6a 100644
--- a/apps/client/src/widgets/collections/geomap/SearchBox.tsx
+++ b/apps/client/src/widgets/collections/geomap/SearchBox.tsx
@@ -504,7 +504,8 @@ function pointEntry(query: string): SearchEntry | null {
label: coordinates,
lat,
lng,
- zoom: POINT_ZOOM
+ zoom: POINT_ZOOM,
+ unnamed: true
}
};
}
diff --git a/apps/client/src/widgets/collections/geomap/api.spec.ts b/apps/client/src/widgets/collections/geomap/api.spec.ts
index 577d7b3ff2..5da40868ee 100644
--- a/apps/client/src/widgets/collections/geomap/api.spec.ts
+++ b/apps/client/src/widgets/collections/geomap/api.spec.ts
@@ -17,6 +17,10 @@ vi.mock("../../../services/note_create", () => ({
default: { createNote: vi.fn(async () => ({ note: { noteId: "created" }, branch: null })) }
}));
+// i18next is not initialized under test, so t() returns nothing. The key stands in for the text,
+// which is enough to tell the stock name from a name the place brought with it.
+vi.mock("../../../services/i18n", () => ({ t: (key: string) => key }));
+
vi.mock("../../../services/attributes", () => ({ default: { setLabel: vi.fn(async () => {}) } }));
vi.mock("../../../services/note_deletion", () => ({ deleteNoteOrBranch: vi.fn(async () => {}) }));
vi.mock("../../../services/dialog", () => ({
@@ -45,6 +49,7 @@ describe("geo map api", () => {
expect(createNote).toHaveBeenCalledWith(parent.noteId, expect.objectContaining({
type: "text",
// Nothing is asked first — the name is typed over in the pane, not answered in a modal.
+ title: "relation_map.default_new_note_title",
activate: false,
attributes: expect.arrayContaining([
{ type: "label", name: "geolocation", value: "48.85,2.36" },
@@ -71,6 +76,22 @@ describe("geo map api", () => {
}));
});
+ it("gives a note kept from a bare point the name a placed marker gets", async () => {
+ const parent = buildNote({ title: "The map" });
+
+ // A point read out of the search bar is called by its own coordinates, which is no title.
+ const created = await createNoteForPlace(
+ parent, { name: "45.796, 24.147", lat: 45.796, lng: 24.147, unnamed: true });
+
+ expect(created).toEqual({ noteId: "created" });
+ expect(createNote).toHaveBeenCalledWith(parent.noteId, expect.objectContaining({
+ title: "relation_map.default_new_note_title",
+ attributes: expect.arrayContaining([
+ { type: "label", name: "geolocation", value: "45.796,24.147" }
+ ])
+ }));
+ });
+
it("brings a GPX file in as a file note the map draws tracks by", async () => {
const parent = buildNote({ title: "The map" });
const file = new File([ "<gpx><trk/></gpx>" ], "sunday-ride.gpx");
diff --git a/apps/client/src/widgets/collections/geomap/api.ts b/apps/client/src/widgets/collections/geomap/api.ts
index 997247589c..1c74f184e1 100644
--- a/apps/client/src/widgets/collections/geomap/api.ts
+++ b/apps/client/src/widgets/collections/geomap/api.ts
@@ -98,14 +98,28 @@ export async function createNewNote(parentNote: FNote, e: GeoMouseEvent) {
}
/**
- * Turns a place found by searching into a note of the map's own, named as the geocoder names it.
+ * Turns a place into a note of the map's own, named as the place is named.
*
- * Unlike a note dropped by clicking the map, this one arrives with a name worth keeping, so the
- * detail pane opens on it as it stands rather than with the title picked out to be typed over (see
- * `isNew` in DetailPane).
+ * Unlike a note dropped by clicking the map, this one usually arrives with a name worth keeping, so
+ * the detail pane opens on it as it stands rather than with the title picked out to be typed over
+ * (see `isNew` in DetailPane).
+ *
+ * A place named only by where it stands is the exception: a point read out of the search bar is
+ * called by its own coordinates, which is no title for a note. It takes the name a placed marker
+ * takes instead, and the pane opens on it the same way (see `keepPlaceAsMarker` in index).
*/
-export async function createNoteForPlace(parentNote: FNote, place: { name: string; lat: number; lng: number }) {
- return createNoteAt(parentNote, [ place.lat, place.lng ], place.name);
+export async function createNoteForPlace(parentNote: FNote, place: PlaceToKeep) {
+ const title = place.unnamed ? t("relation_map.default_new_note_title") : place.name;
+
+ return createNoteAt(parentNote, [ place.lat, place.lng ], title);
+}
+
+/** What keeping a place as a marker needs of it: where it stands, and what to call it there. */
+interface PlaceToKeep {
+ name: string;
+ lat: number;
+ lng: number;
+ unnamed?: boolean;
}
async function createNoteAt(parentNote: FNote, [ lat, lng ]: [number, number], title: string) {
diff --git a/apps/client/src/widgets/collections/geomap/geocoding.ts b/apps/client/src/widgets/collections/geomap/geocoding.ts
index 6a8fbcee6a..fb257339cb 100644
--- a/apps/client/src/widgets/collections/geomap/geocoding.ts
+++ b/apps/client/src/widgets/collections/geomap/geocoding.ts
@@ -58,6 +58,12 @@ export interface GeoSearchResult {
* a place of unsaid extent: a point named by its coordinates is meant exactly.
*/
zoom?: number;
+ /**
+ * Whether the place is named only by where it stands, as a point read out of the search bar is.
+ * A note kept from one has nothing to be called, so it takes the name a placed marker takes
+ * (see `createNoteForPlace` in api and `keepPlaceAsMarker` in index).
+ */
+ unnamed?: boolean;
/**
* Fetches the boundary of the place — a country's coastline, a county's border — or `null` where
* it has none worth drawing. Absent where the provider cannot supply one at all.
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index 33cddc5971..9399460003 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -217,7 +217,9 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
if (!created) return;
setNotes((current) => current.some((n) => n.noteId === created.noteId) ? current : [ ...current, created ]);
- selectNote({ noteId: created.noteId });
+ // A place named only by where it stands gave the note nothing to be called, so the pane
+ // opens with the stock title picked out, exactly as it does over a marker just placed.
+ selectNote({ noteId: created.noteId, isNew: pickedPlace.unnamed });
}, [ note, pickedPlace, selectNote ]);
const toggleNotePlacement = useCallback(() => {
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
index 3064549929..2c20ce385c 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map.html
@@ -88,6 +88,10 @@
above everything else, and taking it flies the map to that exact spot and
marks it, so it can be kept as a marker in the same way a searched place
can.</p>
+<p>A point has no name of its own, only the coordinates it was typed as. The
+ note kept from one is therefore created under the same stock name a marker
+ placed with the <em>Add marker</em> button gets, and opens with that title
+ selected, ready to be typed over.</p>
<p>The forms understood are:</p>
<ul>
<li>A plain pair, <code spellcheck="false">45.9432, 24.9668</code> — what both Google Maps and
diff --git a/docs/User Guide/User Guide/Collections/Geo Map.md b/docs/User Guide/User Guide/Collections/Geo Map.md
index 4f63fad069..2a7bd59a5d 100644
--- a/docs/User Guide/User Guide/Collections/Geo Map.md
+++ b/docs/User Guide/User Guide/Collections/Geo Map.md
@@ -62,6 +62,8 @@ The search prefers what the map is showing. Places inside the current view are l
Coordinates typed or pasted into the search bar are offered as a _Go to_ row above everything else, and taking it flies the map to that exact spot and marks it, so it can be kept as a marker in the same way a searched place can.
+A point has no name of its own, only the coordinates it was typed as. The note kept from one is therefore created under the same stock name a marker placed with the _Add marker_ button gets, and opens with that title selected, ready to be typed over.
+
The forms understood are:
* A plain pair, `45.9432, 24.9668` — what both Google Maps and OpenStreetMap give when asked for a place's coordinates, and what the `#geolocation` attribute holds.