Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): let a custom map style say that it is a dark one

Elian Doran6b1e3141f473
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index a31680cde4..5136fbdfcc 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -752,6 +752,7 @@
"geolocation": "The latitude and longitude the note is placed at on a geo map.",
"map_type": "Which note map is drawn: <code>link</code> for the relations between notes, or <code>tree</code> for the hierarchy.",
"map_style": "Which style a geo map is drawn in, chosen from the raster and vector styles offered in the collection properties.",
+ "map_dark_style": "Tells a geo map that the custom style given in <code>map:style</code> is a dark one, so that the marker titles are drawn light over it. The styles offered in the collection properties say so for themselves and need no such label.",
"map_scale": "Shows a scale bar on the geo map.",
"map_hide_labels": "Hides the note titles beside the markers on a geo map.",
"map_cluster": "Gathers markers that are drawn close together into a single numbered bubble, which opens when clicked.",
diff --git a/apps/client/src/widgets/attribute_widgets/attr_help.ts b/apps/client/src/widgets/attribute_widgets/attr_help.ts
index bbae99c8f3..4a1b732475 100644
--- a/apps/client/src/widgets/attribute_widgets/attr_help.ts
+++ b/apps/client/src/widgets/attribute_widgets/attr_help.ts
@@ -175,6 +175,7 @@ export const ATTR_HELP: AttrHelpMap = {
geolocation: t("attribute_detail.geolocation"),
mapType: t("attribute_detail.map_type"),
"map:style": t("attribute_detail.map_style"),
+ "map:darkStyle": t("attribute_detail.map_dark_style"),
"map:scale": t("attribute_detail.map_scale"),
"map:hideLabels": t("attribute_detail.map_hide_labels"),
"map:cluster": t("attribute_detail.map_cluster"),
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index db7c55b0fe..d1fd1e9d5b 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -186,6 +186,10 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewM
function useLayerData(note: FNote) {
const [ layerName ] = useNoteLabel(note, "map:style");
+ // Whether the style is a dark one, which decides how a marker's title is drawn over it (see
+ // Markers). Only the style itself can say, and a style named by URL says nothing to us: it is
+ // fetched by the map, and its tiles are pictures besides. So the note is asked instead.
+ const [ isDarkStyle ] = useNoteLabelBoolean(note, "map:darkStyle");
// Memo is needed because it would generate unnecessary reloads due to layer change.
const layerData = useMemo(() => {
// Custom layers.
@@ -194,14 +198,17 @@ function useLayerData(note: FNote) {
name: "Custom",
type: "raster",
url: layerName,
- attribution: ""
+ attribution: "",
+ isDarkTheme: isDarkStyle
} satisfies MapLayer;
}
- // Built-in layers.
+ // Built-in layers, which declare it for themselves. The label is still honoured over one, so
+ // that setting it does something wherever it is set; it can only ever say that a style is
+ // dark, never that it is light, so a built-in dark style keeps its own answer either way.
const layerData = MAP_LAYERS[layerName ?? ""] ?? MAP_LAYERS[DEFAULT_MAP_LAYER_NAME];
- return layerData;
- }, [ layerName ]);
+ return isDarkStyle ? { ...layerData, isDarkTheme: true } : layerData;
+ }, [ layerName, isDarkStyle ]);
return layerData;
}
diff --git a/packages/commons/src/lib/builtin_attributes.ts b/packages/commons/src/lib/builtin_attributes.ts
index 987408c605..e1dc4032e7 100644
--- a/packages/commons/src/lib/builtin_attributes.ts
+++ b/packages/commons/src/lib/builtin_attributes.ts
@@ -292,6 +292,9 @@ const BUILTIN_ATTRIBUTES = [
"link", "tree"
] },
{ type: "label", name: "map:style", valueType: "text", hasUserValue: true },
+ // Says of a style Trilium knows nothing about that it is a dark one, which only the style itself
+ // can tell. The styles offered in the collection properties declare it for themselves.
+ { type: "label", name: "map:darkStyle", valueType: "boolean", hasUserValue: true },
{ type: "label", name: "map:scale", valueType: "boolean", hasUserValue: true },
{ type: "label", name: "map:hideLabels", valueType: "boolean", hasUserValue: true },
{ type: "label", name: "map:cluster", valueType: "boolean", hasUserValue: true },