Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): automatic light/dark mode themes

Elian Dorand37ddd3268e6
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 0e4bce7c62..09286b7f20 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3385,6 +3385,7 @@
"raster": "Raster",
"vector_light": "Vector (Light)",
"vector_dark": "Vector (Dark)",
+ "vector_auto": "Vector (Auto)",
"show-scale": "Show scale",
"show-labels": "Show marker names",
"cluster-markers": "Group nearby markers",
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index c242601c16..e65cc76259 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -11,7 +11,7 @@ import server from "../../../services/server";
import toast from "../../../services/toast";
import { logError } from "../../../services/ws";
import CollectionProperties from "../../note_bars/CollectionProperties";
-import { useCollectionTreeDrag, useEffectiveReadOnly, useNoteBlob, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useSpacedUpdate } from "../../react/hooks";
+import { useCollectionTreeDrag, useColorScheme, useEffectiveReadOnly, useNoteBlob, useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useSpacedUpdate } from "../../react/hooks";
import { ViewModeProps } from "../interface";
import { createNewNote, createNoteForPlace, importGpxTrack, moveMarker } from "./api";
import Buildings from "./Buildings";
@@ -460,6 +460,7 @@ function useLayerData(note: FNote) {
// 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");
+ const isSystemDark = useColorScheme() === "dark";
// Memo is needed because it would generate unnecessary reloads due to layer change.
const layerData = useMemo(() => {
// Custom layers.
@@ -477,8 +478,18 @@ function useLayerData(note: FNote) {
// 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];
+
+ // Automatic dark/light style switching based on the system color scheme.
+ if ("styleDark" in layerData) {
+ return {
+ ...layerData,
+ style: isSystemDark ? layerData.styleDark : layerData.styleLight,
+ isDarkTheme: isSystemDark
+ } satisfies MapLayer;
+ }
+
return isDarkStyle ? { ...layerData, isDarkTheme: true } : layerData;
- }, [ layerName, isDarkStyle ]);
+ }, [ layerName, isDarkStyle, isSystemDark ]);
return layerData;
}
diff --git a/apps/client/src/widgets/collections/geomap/map_layer.ts b/apps/client/src/widgets/collections/geomap/map_layer.ts
index 5d8725543a..5de11027af 100644
--- a/apps/client/src/widgets/collections/geomap/map_layer.ts
+++ b/apps/client/src/widgets/collections/geomap/map_layer.ts
@@ -9,6 +9,10 @@ export type MapLayer = ({
* had on the day it was taken.
*/
style: string;
+} | {
+ type: "vector",
+ styleLight: string;
+ styleDark: string;
} | {
type: "raster";
url: string;
@@ -48,25 +52,37 @@ export const MAP_LAYERS: Record<string, MapLayer> = {
style: versatilesStyle("eclipse"),
isDarkTheme: true
},
+ "versatile-colorful-eclipse": {
+ name: "VersaTiles Colorful/Eclipse",
+ type: "vector",
+ styleLight: versatilesStyle("colorful"),
+ styleDark: versatilesStyle("eclipse")
+ },
"versatiles-graybeard": {
name: "VersaTiles Graybeard",
type: "vector",
style: versatilesStyle("graybeard")
},
- "versatiles-neutrino": {
- name: "VersaTiles Neutrino",
- type: "vector",
- style: versatilesStyle("neutrino")
- },
"versatiles-shadow": {
name: "VersaTiles Shadow",
type: "vector",
style: versatilesStyle("shadow"),
isDarkTheme: true
- }
+ },
+ "versatile-graybeard-shadow": {
+ name: "VersaTiles Graybeard/Shadow",
+ type: "vector",
+ styleLight: versatilesStyle("graybeard"),
+ styleDark: versatilesStyle("shadow")
+ },
+ "versatiles-neutrino": {
+ name: "VersaTiles Neutrino",
+ type: "vector",
+ style: versatilesStyle("neutrino")
+ },
};
-export const DEFAULT_MAP_LAYER_NAME: keyof typeof MAP_LAYERS = "versatiles-colorful";
+export const DEFAULT_MAP_LAYER_NAME: keyof typeof MAP_LAYERS = "versatile-colorful-eclipse";
/**
* One of the styles VersaTiles publishes, labelled in English.
diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.tsx b/apps/client/src/widgets/ribbon/collection-properties-config.tsx
index 65fa6cd537..bccaeead2f 100644
--- a/apps/client/src/widgets/ribbon/collection-properties-config.tsx
+++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx
@@ -100,16 +100,22 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {
.filter(([_, layer]) => layer.type === "raster")
.map(buildMapLayer)
},
+ {
+ title: t("book_properties_config.vector_auto"),
+ items: Object.entries(MAP_LAYERS)
+ .filter(([_, layer]) => layer.type === "vector" && "styleDark" in layer)
+ .map(buildMapLayer)
+ },
{
title: t("book_properties_config.vector_light"),
items: Object.entries(MAP_LAYERS)
- .filter(([_, layer]) => layer.type === "vector" && !layer.isDarkTheme)
+ .filter(([_, layer]) => layer.type === "vector" && !layer.isDarkTheme && !("styleDark" in layer))
.map(buildMapLayer)
},
{
title: t("book_properties_config.vector_dark"),
items: Object.entries(MAP_LAYERS)
- .filter(([_, layer]) => layer.type === "vector" && layer.isDarkTheme)
+ .filter(([_, layer]) => layer.type === "vector" && layer.isDarkTheme && !("styleDark" in layer))
.map(buildMapLayer)
}
]