Skip to content

Build your personal knowledge base with Trilium Notes

refactor(geomap): rename the image map labels to #mapPosition and #mapShape

Elian Doran45032b066335
diff --git a/apps/client/src/services/attribute_renderer.ts b/apps/client/src/services/attribute_renderer.ts
index cf4923f1ff..2ec3af0e60 100644
--- a/apps/client/src/services/attribute_renderer.ts
+++ b/apps/client/src/services/attribute_renderer.ts
@@ -90,7 +90,7 @@ const HIDDEN_ATTRIBUTES = [
"pageSize",
"viewType",
"geolocation",
- "imagePosition",
+ "mapPosition",
"docName",
"webViewSrc",
"archived"
diff --git a/apps/client/src/widgets/collections/geomap/DetailPane.tsx b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
index a70a840cfd..8a055189a4 100644
--- a/apps/client/src/widgets/collections/geomap/DetailPane.tsx
+++ b/apps/client/src/widgets/collections/geomap/DetailPane.tsx
@@ -1,6 +1,6 @@
import "./DetailPane.css";
-import { GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, IMAGE_POSITION_ATTRIBUTE, IMAGE_SHAPE_ATTRIBUTE } from "@triliumnext/commons";
+import { GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, MAP_POSITION_ATTRIBUTE, MAP_SHAPE_ATTRIBUTE } from "@triliumnext/commons";
import type { EaseToOptions, GeoJSONSource, MapGeoJSONFeature, Map as MapLibreGLMap, MapMouseEvent, MapSourceDataEvent } from "maplibre-gl";
import { useCallback, useContext, useEffect, useMemo, useRef } from "preact/hooks";
@@ -461,7 +461,7 @@ function MarkerContents({ note, parentNote, isReadOnly, onRelocate }: {
/** The labels that put a note on a map, of either space. */
const OMITTED_ATTRIBUTES = [
- GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, IMAGE_POSITION_ATTRIBUTE, IMAGE_SHAPE_ATTRIBUTE
+ GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, MAP_POSITION_ATTRIBUTE, MAP_SHAPE_ATTRIBUTE
];
/** The start of the ntxId of the pane's own note context. */
diff --git a/apps/client/src/widgets/collections/geomap/api.spec.ts b/apps/client/src/widgets/collections/geomap/api.spec.ts
index ef1d172c4d..8a6a63f3c4 100644
--- a/apps/client/src/widgets/collections/geomap/api.spec.ts
+++ b/apps/client/src/widgets/collections/geomap/api.spec.ts
@@ -195,7 +195,7 @@ describe("geo map api", () => {
await removeFromMap(imageSpace({ width: 100, height: 100 }), track, map);
expect(confirmDelete).toHaveBeenLastCalledWith(track.title, expect.anything(), expect.objectContaining({ mustDeleteNote: false }));
- expect(setLabel).toHaveBeenLastCalledWith(track.noteId, "imagePosition", "");
+ expect(setLabel).toHaveBeenLastCalledWith(track.noteId, "mapPosition", "");
});
it("leaves the marker alone where the reader changed their mind", async () => {
diff --git a/apps/client/src/widgets/collections/geomap/space.spec.ts b/apps/client/src/widgets/collections/geomap/space.spec.ts
index b9dba8f76b..d6ca7f2606 100644
--- a/apps/client/src/widgets/collections/geomap/space.spec.ts
+++ b/apps/client/src/widgets/collections/geomap/space.spec.ts
@@ -72,8 +72,8 @@ describe("imageSpace", () => {
});
it("reads the labels of its own space only", () => {
- const marker = buildNote({ title: "Tavern", "#imagePosition": "10,20", "#geolocation": "1,2" });
- const shape = buildNote({ title: "Road", "#imageShape": "line:0,0 10,10" });
+ const marker = buildNote({ title: "Tavern", "#mapPosition": "10,20", "#geolocation": "1,2" });
+ const shape = buildNote({ title: "Road", "#mapShape": "line:0,0 10,10" });
expect(locationOf(marker, space)).toEqual(space.parseLocation("10,20"));
expect(locationOf(marker, geoSpace)).toEqual([ 2, 1 ]);
diff --git a/apps/client/src/widgets/collections/geomap/space.ts b/apps/client/src/widgets/collections/geomap/space.ts
index c774106785..9c89718ef7 100644
--- a/apps/client/src/widgets/collections/geomap/space.ts
+++ b/apps/client/src/widgets/collections/geomap/space.ts
@@ -4,11 +4,11 @@
* MapLibre knows only longitude and latitude, so everything on the map is held in `[lng, lat]`
* whichever it is. A {@link MapSpace} converts at the edge, where a position is read off a note's
* label or written back onto one: a geo map stores `#geolocation` and `#geoShape` in degrees, an
- * image map `#imagePosition` and `#imageShape` in a coordinate system the map names for its image
+ * image map `#mapPosition` and `#mapShape` in a coordinate system the map names for its image
* (see {@link imageSpace}).
*/
-import { GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, IMAGE_POSITION_ATTRIBUTE, IMAGE_SHAPE_ATTRIBUTE } from "@triliumnext/commons";
+import { GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, MAP_POSITION_ATTRIBUTE, MAP_SHAPE_ATTRIBUTE } from "@triliumnext/commons";
import { MercatorCoordinate } from "maplibre-gl";
import { createContext } from "preact";
@@ -217,8 +217,8 @@ export function imageSpace({ width, height }: ImageSize, extent?: ImageExtent |
return {
kind: "image",
- locationAttribute: IMAGE_POSITION_ATTRIBUTE,
- shapeAttribute: IMAGE_SHAPE_ATTRIBUTE,
+ locationAttribute: MAP_POSITION_ATTRIBUTE,
+ shapeAttribute: MAP_SHAPE_ATTRIBUTE,
corners: [ topLeftLngLat, pixelToLngLat([ width, 0 ]), bottomRightLngLat, pixelToLngLat([ 0, height ]) ],
bounds: [ [ topLeftLngLat[0], bottomRightLngLat[1] ], [ bottomRightLngLat[0], topLeftLngLat[1] ] ],
maxBounds: [ [ west, south ], [ east, north ] ],
diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts
index 6434d0e09b..0e8247d32e 100644
--- a/apps/client/src/widgets/note_tree.ts
+++ b/apps/client/src/widgets/note_tree.ts
@@ -5,7 +5,7 @@ import "jquery.fancytree/dist/modules/jquery.fancytree.filter.js";
import "../stylesheets/tree.css";
import "./note_tree.css";
-import { GEO_LOCATION_ATTRIBUTE, IMAGE_POSITION_ATTRIBUTE } from "@triliumnext/commons";
+import { GEO_LOCATION_ATTRIBUTE, MAP_POSITION_ATTRIBUTE } from "@triliumnext/commons";
import appContext, { type CommandListenerData, type EventData } from "../components/app_context.js";
import type { SetNoteOpts } from "../components/note_context.js";
@@ -1306,10 +1306,10 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
#processAttributeRows(attributeRows: AttributeRow[], refreshCtx: RefreshContext) {
for (const attrRow of attributeRows) {
- // `geolocation` and `imagePosition` decide the icon of a note that has none of its own
+ // `geolocation` and `mapPosition` decide the icon of a note that has none of its own
// (see getNoteIcon).
const dirtyingLabels = ["iconClass", "cssClass", "workspace", "workspaceIconClass",
- "color", GEO_LOCATION_ATTRIBUTE, IMAGE_POSITION_ATTRIBUTE];
+ "color", GEO_LOCATION_ATTRIBUTE, MAP_POSITION_ATTRIBUTE];
if (attrRow.type === "label" && dirtyingLabels.includes(attrRow.name ?? "") && attrRow.noteId) {
if (attrRow.isInheritable) {
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 28a11c4e1f..51eab980ef 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
@@ -292,7 +292,7 @@
of the child notes:</p>
<p>This value can be added manually if needed. The value of the attribute
is made up of the latitude and longitude separated by a comma.</p>
-<p>On an image map, the position is stored in <code>#imagePosition</code> instead
+<p>On an image map, the position is stored in <code>#mapPosition</code> instead
(see&nbsp;<a class="reference-link" href="#root/_help_ZRDXGc0nAIh4">Image maps</a>).</p>
<h2>Repositioning markers</h2>
<p>Once a marker is set, it can be repositioned using one of the two ways:</p>
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map/Image maps.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map/Image maps.html
index fc50e9a035..eab240cdc7 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map/Image maps.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Geo Map/Image maps.html
@@ -52,7 +52,7 @@ class="admonition note">
<ul>
<li>A screenshot of a game map that covers <code>x</code> from -512 to 512 and <code>y</code> from
-512 to 512, with <code>y</code> growing downwards: <code>#map:imageBounds=-512,-512 512,512</code>.
- Coordinates copied from the game can then be pasted directly into <code>#imagePosition</code>.</li>
+ Coordinates copied from the game can then be pasted directly into <code>#mapPosition</code>.</li>
<li>A world whose <code>y</code> grows upwards, with the origin in the middle
of the image: <code>#map:imageBounds=-2000,1000 2000,-1000</code>. A top-left <code>y</code> larger
than the bottom-right one is what flips the axis.</li>
@@ -77,16 +77,16 @@ class="table">
</thead>
<tbody>
<tr>
- <td><code>#imagePosition</code>
+ <td><code>#mapPosition</code>
</td>
- <td>The position of a marker, as <code>x,y</code>, for example <code>#imagePosition=320,145</code>.</td>
+ <td>The position of a marker, as <code>x,y</code>, for example <code>#mapPosition=320,145</code>.</td>
</tr>
<tr>
- <td><code>#imageShape</code>
+ <td><code>#mapShape</code>
</td>
<td>A shape, in the same format as <code>#geoShape</code> (see&nbsp;<a class="reference-link"
href="#root/_help_C2H9HK4BzwG7">Drawing shapes</a>) but with <code>x,y</code> pairs,
- and a circle's radius in the map's units, for example <code>#imageShape=circle:400,300 50</code>.</td>
+ and a circle's radius in the map's units, for example <code>#mapShape=circle:400,300 50</code>.</td>
</tr>
</tbody>
</table>
diff --git a/docs/User Guide/User Guide/Collections/Geo Map.md b/docs/User Guide/User Guide/Collections/Geo Map.md
index 807ce754cb..b822de79fd 100644
--- a/docs/User Guide/User Guide/Collections/Geo Map.md
+++ b/docs/User Guide/User Guide/Collections/Geo Map.md
@@ -189,7 +189,7 @@ The location of a marker is stored in the `#geolocation` attribute of the child
This value can be added manually if needed. The value of the attribute is made up of the latitude and longitude separated by a comma.
-On an image map, the position is stored in `#imagePosition` instead (see <a class="reference-link" href="Geo%20Map/Image%20maps.md">Image maps</a>).
+On an image map, the position is stored in `#mapPosition` instead (see <a class="reference-link" href="Geo%20Map/Image%20maps.md">Image maps</a>).
## Repositioning markers
diff --git a/docs/User Guide/User Guide/Collections/Geo Map/Image maps.md b/docs/User Guide/User Guide/Collections/Geo Map/Image maps.md
index c27f3ac182..898ddbddf8 100644
--- a/docs/User Guide/User Guide/Collections/Geo Map/Image maps.md
+++ b/docs/User Guide/User Guide/Collections/Geo Map/Image maps.md
@@ -33,7 +33,7 @@ By default, positions are measured in pixels of the image at its original size,
To use coordinates of your own instead, add a `#map:imageBounds` label to the geo map, naming the coordinates of the image's top-left corner and of its bottom-right corner as `x,y x,y`, with a space between the two corners. All positions are then read and written in those coordinates, including the ones shown in the contextual menu and in the popup view. For example:
-* A screenshot of a game map that covers `x` from -512 to 512 and `y` from -512 to 512, with `y` growing downwards: `#map:imageBounds=-512,-512 512,512`. Coordinates copied from the game can then be pasted directly into `#imagePosition`.
+* A screenshot of a game map that covers `x` from -512 to 512 and `y` from -512 to 512, with `y` growing downwards: `#map:imageBounds=-512,-512 512,512`. Coordinates copied from the game can then be pasted directly into `#mapPosition`.
* A world whose `y` grows upwards, with the origin in the middle of the image: `#map:imageBounds=-2000,1000 2000,-1000`. A top-left `y` larger than the bottom-right one is what flips the axis.
* A floor plan measured in meters: `#map:imageBounds=0,0 24,12`.
@@ -47,8 +47,8 @@ Because positions are stored in different labels from the ones of a geo map, the
| Label | Content |
| --- | --- |
-| `#imagePosition` | The position of a marker, as `x,y`, for example `#imagePosition=320,145`. |
-| `#imageShape` | A shape, in the same format as `#geoShape` (see <a class="reference-link" href="Drawing%20shapes.md">Drawing shapes</a>) but with `x,y` pairs, and a circle's radius in the map's units, for example `#imageShape=circle:400,300 50`. |
+| `#mapPosition` | The position of a marker, as `x,y`, for example `#mapPosition=320,145`. |
+| `#mapShape` | A shape, in the same format as `#geoShape` (see <a class="reference-link" href="Drawing%20shapes.md">Drawing shapes</a>) but with `x,y` pairs, and a circle's radius in the map's units, for example `#mapShape=circle:400,300 50`. |
The positions belong to the coordinate system, not to the image. When replacing the image with a different one, for example a higher-resolution copy, keep `#map:imageBounds` describing the area the new image covers and every marker stays in place. Without `#map:imageBounds`, the positions are pixels, so an image of a different size moves the markers relative to what the image shows; to avoid that, set `#map:imageBounds` to the size of the old image (`0,0 <width>,<height>`) before replacing it.
diff --git a/packages/commons/src/lib/builtin_attributes.ts b/packages/commons/src/lib/builtin_attributes.ts
index a8f20c70d5..dcabb85d5a 100644
--- a/packages/commons/src/lib/builtin_attributes.ts
+++ b/packages/commons/src/lib/builtin_attributes.ts
@@ -303,8 +303,8 @@ const BUILTIN_ATTRIBUTES = [
{ type: "label", name: "geoShape", valueType: "text", hasUserValue: true },
// The counterparts of `geolocation` and `geoShape` on a map drawn over an image (`~map:image`):
// `x,y` in the map's coordinates, which are the image's own pixels unless the map names others.
- { type: "label", name: "imagePosition", valueType: "text", hasUserValue: true },
- { type: "label", name: "imageShape", valueType: "text", hasUserValue: true },
+ { type: "label", name: "mapPosition", valueType: "text", hasUserValue: true },
+ { type: "label", name: "mapShape", valueType: "text", hasUserValue: true },
// The coordinates of an image map's top-left and bottom-right corners, as `x,y x,y`.
{ type: "label", name: "map:imageBounds", valueType: "text", hasUserValue: true },
// Which note map a note map note draws; anything but `tree` is read as `link`.
diff --git a/packages/commons/src/lib/notes.spec.ts b/packages/commons/src/lib/notes.spec.ts
index d4bc8783b6..7e2bfb50b9 100644
--- a/packages/commons/src/lib/notes.spec.ts
+++ b/packages/commons/src/lib/notes.spec.ts
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import {
CANVAS_ATTACHMENT_MIME, GEO_LOCATION_ATTRIBUTE, GEO_SHAPE_ATTRIBUTE, getImageAttachmentTitle,
- getMimeIcon, getNoteIcon, IMAGE_POSITION_ATTRIBUTE, IMAGE_SHAPE_ATTRIBUTE,
+ getMimeIcon, getNoteIcon, MAP_POSITION_ATTRIBUTE, MAP_SHAPE_ATTRIBUTE,
NOTE_TYPE_ICONS, NOTE_TYPE_IMAGE_ATTACHMENTS, parseMindMapNoteLink
} from "./notes.js";
import { NoteType } from "./rows.js";
@@ -131,16 +131,16 @@ describe("getNoteIcon", () => {
expect(getNoteIcon(buildArgs({ getLabelValue: drawn("") }))).toBe("bx bx-note");
});
- it("draws the notes of an image map by their pixel labels, as it does those of a geo map", () => {
+ it("draws the notes of an image map by their map labels, as it does those of a geo map", () => {
const labelled = (labels: Record<string, string>) => (name: string) => labels[name] ?? null;
- expect(getNoteIcon(buildArgs({ getLabelValue: labelled({ [IMAGE_POSITION_ATTRIBUTE]: "10,20" }) })))
+ expect(getNoteIcon(buildArgs({ getLabelValue: labelled({ [MAP_POSITION_ATTRIBUTE]: "10,20" }) })))
.toBe("bx bx-pin");
- expect(getNoteIcon(buildArgs({ getLabelValue: labelled({ [IMAGE_SHAPE_ATTRIBUTE]: "circle:10,20 5" }) })))
+ expect(getNoteIcon(buildArgs({ getLabelValue: labelled({ [MAP_SHAPE_ATTRIBUTE]: "circle:10,20 5" }) })))
.toBe("bx bx-shape-circle");
// A note taken off a geo map keeps an empty `#geoShape`, which leaves the image's to answer.
expect(getNoteIcon(buildArgs({
- getLabelValue: labelled({ [GEO_SHAPE_ATTRIBUTE]: "", [IMAGE_SHAPE_ATTRIBUTE]: "polygon:0,0 1,0 1,1" })
+ getLabelValue: labelled({ [GEO_SHAPE_ATTRIBUTE]: "", [MAP_SHAPE_ATTRIBUTE]: "polygon:0,0 1,0 1,1" })
}))).toBe("bx bx-shape-polygon");
});
diff --git a/packages/commons/src/lib/notes.ts b/packages/commons/src/lib/notes.ts
index 23f7906f51..1fa17fbfd9 100644
--- a/packages/commons/src/lib/notes.ts
+++ b/packages/commons/src/lib/notes.ts
@@ -115,9 +115,10 @@ const IMAGE_MIME_MAPPINGS: Record<string, string> = {
export const GEO_LOCATION_ATTRIBUTE = "geolocation";
export const GEO_SHAPE_ATTRIBUTE = "geoShape";
-/** The same two labels on a map drawn over an image, holding pixels rather than degrees. */
-export const IMAGE_POSITION_ATTRIBUTE = "imagePosition";
-export const IMAGE_SHAPE_ATTRIBUTE = "imageShape";
+/** The same two labels on a map drawn over an image, in the map's own coordinates rather than
+ * degrees. */
+export const MAP_POSITION_ATTRIBUTE = "mapPosition";
+export const MAP_SHAPE_ATTRIBUTE = "mapShape";
/** The icon a note on a geo map is drawn under where it has none of its own. */
export const GEO_MARKER_ICON = "bx bx-pin";
@@ -136,9 +137,10 @@ export const GEO_SHAPE_ICONS: Record<string, string> = {
* The icon a note is drawn under: its own `#iconClass` where it has one, and a default read off
* what the note is otherwise.
*
- * A note carrying a non-empty `#geolocation` or `#imagePosition` is drawn as a pin, and one carrying
- * a `#geoShape` or `#imageShape` as the shape it names, where neither has anything more specific. The geo map therefore writes no
- * `#iconClass` onto a marker or a shape it creates, so an icon it hands down through
+ * A note carrying a non-empty `#geolocation` or `#mapPosition` is drawn as a pin, and one carrying
+ * a `#geoShape` or `#mapShape` as the shape it names, where neither has anything more specific.
+ * The geo map therefore writes no `#iconClass` onto a marker or a shape it creates, so an icon it
+ * hands down through
* `#child:iconClass` or a template still applies, and redrawing a shape as another kind changes the
* icon with it. `iconClass` stays an argument rather than being read here because the share tree
* narrows it to the prefixes an icon pack supplies.
@@ -167,10 +169,10 @@ export function getNoteIcon({
} else if (type === "text") {
// A place on a map is written onto a note deliberately, so it outranks the folder icon the
// note picks up from having children.
- if (getLabelValue(GEO_LOCATION_ATTRIBUTE) || getLabelValue(IMAGE_POSITION_ATTRIBUTE)) {
+ if (getLabelValue(GEO_LOCATION_ATTRIBUTE) || getLabelValue(MAP_POSITION_ATTRIBUTE)) {
return GEO_MARKER_ICON;
}
- const shape = getLabelValue(GEO_SHAPE_ATTRIBUTE) || getLabelValue(IMAGE_SHAPE_ATTRIBUTE);
+ const shape = getLabelValue(GEO_SHAPE_ATTRIBUTE) || getLabelValue(MAP_SHAPE_ATTRIBUTE);
if (shape) {
return GEO_SHAPE_ICONS[shape.split(":", 1)[0]] ?? GEO_SHAPE_ICONS.line;
}