Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): drop the white disc behind marker icons

Elian Dorana9260d1305b3
diff --git a/apps/client/src/widgets/collections/geomap/Markers.tsx b/apps/client/src/widgets/collections/geomap/Markers.tsx
index 148e40ad6a..be91443d33 100644
--- a/apps/client/src/widgets/collections/geomap/Markers.tsx
+++ b/apps/client/src/widgets/collections/geomap/Markers.tsx
@@ -2,6 +2,7 @@ import { AddLayerObject, type GeoJSONSource } from "maplibre-gl";
import { useContext, useEffect, useState } from "preact/hooks";
import FNote from "../../../entities/fnote";
+import { getReadableTextColor } from "../../../services/css_class_manager";
import { renderIconImage } from "../../../services/icon_glyphs";
import { useTriliumEvent } from "../../react/hooks";
import { ParentMap } from "./map";
@@ -15,8 +16,9 @@ const DEFAULT_MARKER_COLOR = "#2A81CB";
const MARKER_WIDTH = 25;
const MARKER_HEIGHT = 41;
const MARKER_ICON_SIZE = 20;
+// Centred on the pin's round head, which is a circle of the pin's own width sitting at the top.
const MARKER_ICON_X = (MARKER_WIDTH - MARKER_ICON_SIZE) / 2;
-const MARKER_ICON_Y = 4;
+const MARKER_ICON_Y = (MARKER_WIDTH - MARKER_ICON_SIZE) / 2;
const LABEL_LAYOUT: Extract<AddLayerObject, { type: "symbol" }>["layout"] = {
"text-field": [ "get", "name" ],
@@ -187,17 +189,18 @@ function buildMarkerImage(color: string, iconClass: string) {
async function drawMarkerImage(color: string, iconClass: string) {
// Drawn through the shared icon service, so a marker wears the icon its note wears everywhere
- // else — including one from a pack the user brought along.
+ // else — including one from a pack the user brought along. It is cut straight out of the pin
+ // rather than set on a disc of its own, so the note's colour is all that is seen; the icon
+ // takes whichever of black or white stands out against that colour.
const scale = window.devicePixelRatio || 1;
const icon = await renderIconImage(`bx ${iconClass}`, {
size: MARKER_ICON_SIZE,
- color: "black",
+ color: getReadableTextColor(color),
scale
});
const badge = icon
- ? `<circle cx="${MARKER_WIDTH / 2}" cy="${MARKER_ICON_Y + MARKER_ICON_SIZE / 2}" r="${MARKER_ICON_SIZE / 2}" fill="white" />
- <image href="${icon}" x="${MARKER_ICON_X}" y="${MARKER_ICON_Y}" width="${MARKER_ICON_SIZE}" height="${MARKER_ICON_SIZE}" preserveAspectRatio="xMidYMid meet" />`
+ ? `<image href="${icon}" x="${MARKER_ICON_X}" y="${MARKER_ICON_Y}" width="${MARKER_ICON_SIZE}" height="${MARKER_ICON_SIZE}" preserveAspectRatio="xMidYMid meet" />`
: "";
return svgToImage(`\
diff --git a/apps/client/src/widgets/collections/geomap/index.css b/apps/client/src/widgets/collections/geomap/index.css
index b83498db52..eef226b1e8 100644
--- a/apps/client/src/widgets/collections/geomap/index.css
+++ b/apps/client/src/widgets/collections/geomap/index.css
@@ -42,14 +42,12 @@
filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.3));
}
+/* Cut straight out of the pin — no disc behind it, so only the note's colour is seen. */
.geo-map-container .geo-marker .tn-icon {
position: absolute;
- top: 3px;
+ top: 4px;
inset-inline-start: 4px;
- background-color: white;
- color: var(--light-theme-custom-color, black);
- padding: 2px;
- border-radius: 50%;
+ color: white;
font-size: 17px;
}
@@ -57,7 +55,6 @@
.geo-map-container .geo-marker img.tn-icon {
width: 17px;
height: 17px;
- box-sizing: content-box;
display: block;
}
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index f2ddad473b..734fd0e09e 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -5,6 +5,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks"
import FNote from "../../../entities/fnote";
import branches from "../../../services/branches";
+import { getReadableTextColor } from "../../../services/css_class_manager";
import froca from "../../../services/froca";
import { t } from "../../../services/i18n";
import { renderIconImage } from "../../../services/icon_glyphs";
@@ -261,13 +262,17 @@ function NoteGpxTrack({ note, hideLabels }: { note: FNote, hideLabels?: boolean
/>;
}
-// SVG marker pin shape (replaces the Leaflet marker PNG).
-const MARKER_SVG = `<svg width="25" height="41" viewBox="0 0 25 41" xmlns="http://www.w3.org/2000/svg">` +
- `<path d="M12.5 0C5.6 0 0 5.6 0 12.5C0 21.9 12.5 41 12.5 41S25 21.9 25 12.5C25 5.6 19.4 0 12.5 0Z" fill="#2A81CB" />` +
- `<circle cx="12.5" cy="12.5" r="8" fill="white" />` +
- `</svg>`;
+/** The pin shape, filled with whatever colour the note asks for. Replaces the Leaflet marker PNG. */
+function buildMarkerSvg(color: string) {
+ return `<svg width="25" height="41" viewBox="0 0 25 41" xmlns="http://www.w3.org/2000/svg">` +
+ `<path d="M12.5 0C5.6 0 0 5.6 0 12.5C0 21.9 12.5 41 12.5 41S25 21.9 25 12.5C25 5.6 19.4 0 12.5 0Z" fill="${escapeHtml(color)}" />` +
+ `</svg>`;
+}
+
+/** What a pin is filled with where its note asks for no colour of its own. */
+const DEFAULT_MARKER_COLOR = "#2A81CB";
-/** The size the icon badge is drawn at, matching the font size the CSS-styled span used. */
+/** The size the icon is drawn at, matching the font size the CSS-styled span used. */
const MARKER_ICON_SIZE = 17;
/**
@@ -295,19 +300,23 @@ function useIconHtml(bxIconClass: string, colorClass?: string, title?: string, n
}
async function buildIconHtml(bxIconClass: string, colorClass?: string, title?: string, noteIdLink?: string, archived?: boolean) {
+ // The note's colour fills the pin, as it does for the note markers drawn into the symbol layer,
+ // and the icon is cut out of it in whichever of black or white stands out against that.
+ const pinColor = resolveNoteColor(colorClass) ?? DEFAULT_MARKER_COLOR;
+
// Drawn as a picture through the shared icon service (icon_glyphs.ts) rather than styled by
// CSS, so the marker renders any icon pack's icon the way the rest of the app draws it. A
// class the service cannot resolve falls back to the CSS-styled span.
const image = await renderIconImage(`bx ${bxIconClass}`, {
size: MARKER_ICON_SIZE,
- color: resolveIconColor(colorClass)
+ color: getReadableTextColor(pinColor)
});
const icon = image
? `<img class="tn-icon" src="${image}" alt="" />`
- : `<span class="bx ${escapeHtml(bxIconClass)} tn-icon ${escapeHtml(colorClass ?? "")}"></span>`;
+ : `<span class="bx ${escapeHtml(bxIconClass)} tn-icon"></span>`;
let html = /*html*/`\
- <div class="marker-pin">${MARKER_SVG}</div>
+ <div class="marker-pin">${buildMarkerSvg(pinColor)}</div>
${icon}
<span class="title-label">${escapeHtml(title ?? "")}</span>`;
@@ -319,21 +328,21 @@ async function buildIconHtml(bxIconClass: string, colorClass?: string, title?: s
}
/**
- * The concrete colour the marker icon is drawn in: the light-theme variant of the note's colour —
- * the same value the CSS-styled span read from `--light-theme-custom-color` — or black without
- * one. Only the stylesheet knows the adjusted value, so it is read off an element wearing the
- * colour class, the way the icon service reads its glyphs.
+ * The concrete colour a note's colour class stands for — the light-theme variant, the same value
+ * the CSS-styled span used to read from `--light-theme-custom-color`, or `null` for a note that
+ * asks for no colour. Only the stylesheet knows the adjusted value, so it is read off an element
+ * wearing the class, the way the icon service reads its glyphs.
*/
-function resolveIconColor(colorClass?: string) {
+function resolveNoteColor(colorClass?: string) {
if (!colorClass) {
- return "black";
+ return null;
}
const probe = document.createElement("span");
probe.className = colorClass;
document.body.appendChild(probe);
try {
- return getComputedStyle(probe).getPropertyValue("--light-theme-custom-color").trim() || "black";
+ return getComputedStyle(probe).getPropertyValue("--light-theme-custom-color").trim() || null;
} finally {
probe.remove();
}