Skip to content

Build your personal knowledge base with Trilium Notes

feat(geomap): set a custom tileset from the properties dialog

Elian Dorand70fe827355e
diff --git a/apps/client/src/translations/en-GB/translation.json b/apps/client/src/translations/en-GB/translation.json
index 4c7054e11e..b0e3a0d5d3 100644
--- a/apps/client/src/translations/en-GB/translation.json
+++ b/apps/client/src/translations/en-GB/translation.json
@@ -250,6 +250,6 @@
"license": "{{license}} licence"
},
"geo-map": {
- "dark-image-description": "Draws the marker titles in a light colour, so that they can be read over a dark image."
+ "dark-tiles-description": "Draws the marker titles in a light colour, so that they can be read over dark tiles."
}
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 331a455a89..85a61f79fd 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3170,7 +3170,14 @@
"background-image": "Custom image",
"background-map-description": "A world map in one of the vector or raster styles.",
"background-image-description": "An image of your own, such as a floor plan or a fantasy map, with markers and shapes placed on it.",
- "background-image-inherited": "This map's image comes from a parent note or a template, so it can only be switched off there."
+ "background-image-inherited": "This map's image comes from a parent note or a template, so it can only be switched off there.",
+ "background-tiles": "Custom tileset",
+ "background-tiles-description": "A world map drawn from the raster tiles of a server of your choice.",
+ "tiles-url": "Tile URL",
+ "tiles-url-description": "The address of one tile, with {z}, {x} and {y} where the zoom level and the tile's position go. A server with high-resolution tiles can be given {r}, where it expects @2x.",
+ "tiles-url-invalid": "A tile URL starts with http:// or https:// and contains {z}, {x} and {y}, so this change wasn't saved.",
+ "dark-tiles": "Dark tileset",
+ "dark-tiles-description": "Draws the marker titles in a light color, so that they can be read over dark tiles."
},
"embedded_note": {
"open-note": "Open note",
diff --git a/apps/client/src/widgets/collections/geomap/GeoMapProperties.css b/apps/client/src/widgets/collections/geomap/GeoMapProperties.css
index 2f9ba91aed..66bda8f44c 100644
--- a/apps/client/src/widgets/collections/geomap/GeoMapProperties.css
+++ b/apps/client/src/widgets/collections/geomap/GeoMapProperties.css
@@ -8,7 +8,8 @@
}
.geo-map-image-notice,
- .geo-map-coordinates-error {
+ .geo-map-coordinates-error,
+ .geo-map-tiles-url-error {
margin: 0;
}
}
diff --git a/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsx b/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsx
index 6914c5299d..18168885ac 100644
--- a/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsx
+++ b/apps/client/src/widgets/collections/geomap/GeoMapProperties.spec.tsx
@@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type FNote from "../../../entities/fnote";
import froca from "../../../services/froca";
import { buildNote } from "../../../test/easy-froca";
-import GeoMapProperties, { type GeoMapImageState } from "./GeoMapProperties";
+import GeoMapProperties, { type GeoMapImageState, isTileUrlTemplate } from "./GeoMapProperties";
vi.mock("../../../services/i18n", () => ({
t: (key: string) => key
@@ -51,6 +51,7 @@ vi.mock("../../react/NoteAutocomplete", () => ({
}));
const LOADED_IMAGE: GeoMapImageState = { status: "image", size: { width: 2048, height: 1024 } };
+const TILE_URL = "https://tiles.example.org/{z}/{x}/{y}{r}.png";
describe("GeoMapProperties", () => {
let container: HTMLElement;
@@ -131,6 +132,16 @@ describe("GeoMapProperties", () => {
});
}
+ /** Types `value` into `input` and leaves it, which is when a text box commits. */
+ function type(input: HTMLInputElement | null, value: string) {
+ if (!input) throw new Error("no such input");
+ act(() => {
+ input.value = value;
+ input.dispatchEvent(new Event("input", { bubbles: true }));
+ input.dispatchEvent(new FocusEvent("focusout", { bubbles: true }));
+ });
+ }
+
beforeEach(() => {
vi.clearAllMocks();
container = document.createElement("div");
@@ -180,6 +191,7 @@ describe("GeoMapProperties", () => {
expect(backgroundType()).toBe("geo-map.background-map");
expect(openBackgroundTypes().map((item) => item.textContent?.trim())).toEqual([
"geo-map.background-mapgeo-map.background-map-description",
+ "geo-map.background-tilesgeo-map.background-tiles-description",
"geo-map.background-imagegeo-map.background-image-description"
]);
expect(optionTitles(".geo-map-properties-background")).toEqual([
@@ -237,13 +249,82 @@ describe("GeoMapProperties", () => {
const worldMap = openBackgroundTypes().find((item) =>
item.textContent?.trim().startsWith("geo-map.background-map"));
+ const tiles = openBackgroundTypes().find((item) =>
+ item.textContent?.trim().startsWith("geo-map.background-tiles"));
expect(worldMap?.classList.contains("disabled")).toBe(true);
+ expect(tiles?.classList.contains("disabled")).toBe(true);
act(() => worldMap?.click());
expect(mocks.toggleDangerousAttribute).not.toHaveBeenCalled();
expect(backgroundType()).toBe("geo-map.background-image");
expect(note.noteId).toBe("inheritingMap");
});
+ it("draws a tileset once a URL naming its tiles is entered", () => {
+ const note = draw({});
+ choose("geo-map.background-tiles");
+ expect(optionTitles(".geo-map-properties-background")).toEqual([
+ "geo-map.background-type", "geo-map.tiles-url", "geo-map.dark-tiles"
+ ]);
+ expect(mocks.setLabel).not.toHaveBeenCalled();
+
+ const url = query<HTMLInputElement>(".geo-map-tiles-url");
+ type(url, "https://tiles.example.org/map.png");
+ expect(query(".geo-map-tiles-url-error")).not.toBeNull();
+ expect(url?.value).toBe("https://tiles.example.org/map.png");
+ expect(mocks.setLabel).not.toHaveBeenCalled();
+
+ type(url, ` ${TILE_URL} `);
+ expect(query(".geo-map-tiles-url-error")).toBeNull();
+ expect(mocks.setLabel).toHaveBeenCalledWith(note.noteId, "map:style", TILE_URL);
+ });
+
+ it("goes back to a built-in style by disabling the tileset, which it keeps", () => {
+ const note = draw({ "#map:style": TILE_URL });
+ expect(backgroundType()).toBe("geo-map.background-tiles");
+ expect(query<HTMLInputElement>(".geo-map-tiles-url")?.value).toBe(TILE_URL);
+
+ choose("geo-map.background-map");
+ expect(mocks.toggleDangerousAttribute)
+ .toHaveBeenCalledExactlyOnceWith(note, "label", "map:style", false);
+ expect(optionTitles(".geo-map-properties-background")).toEqual([
+ "geo-map.background-type", "book_properties_config.map-style"
+ ]);
+ });
+
+ it("enables a disabled tileset again, and replaces it when another URL is entered", () => {
+ const note = draw({ "#disabled:map:style": TILE_URL });
+ expect(backgroundType()).toBe("geo-map.background-map");
+
+ choose("geo-map.background-tiles");
+ expect(mocks.toggleDangerousAttribute)
+ .toHaveBeenCalledExactlyOnceWith(note, "label", "map:style", true);
+
+ const other = "https://other.example.org/{z}/{y}/{x}";
+ type(query<HTMLInputElement>(".geo-map-tiles-url"), other);
+ expect(mocks.setLabel).toHaveBeenCalledWith(note.noteId, "map:style", other);
+ expect(mocks.removeOwnedLabelByName).toHaveBeenCalledWith(note, "disabled:map:style");
+ });
+
+ it("overrides an inherited tileset with the default style, and disables an image for one", () => {
+ buildNote({
+ title: "Maps",
+ "#map:style(inheritable)": TILE_URL,
+ children: [ { id: "tiledMap", title: "Map" } ]
+ });
+ const tiled = drawNote(froca.notes.tiledMap);
+ choose("geo-map.background-map");
+ expect(mocks.toggleDangerousAttribute).not.toHaveBeenCalled();
+ expect(mocks.setLabel)
+ .toHaveBeenCalledWith(tiled.noteId, "map:style", "versatile-colorful-eclipse");
+
+ vi.clearAllMocks();
+ const imageMap = draw({ "~map:image": "image1", "#map:style": TILE_URL }, LOADED_IMAGE);
+ choose("geo-map.background-tiles");
+ expect(mocks.toggleDangerousAttribute)
+ .toHaveBeenCalledExactlyOnceWith(imageMap, "relation", "map:image", false);
+ expect(backgroundType()).toBe("geo-map.background-tiles");
+ });
+
it("measures in pixels until custom corners are chosen, starting them at the size", () => {
const note = draw({ "~map:image": "image1" }, LOADED_IMAGE);
expect(query(".autocomplete-stub")?.dataset.noteId).toBe("image1");
@@ -303,3 +384,13 @@ describe("GeoMapProperties", () => {
expect(query(".geo-map-image-notice")).toBeNull();
});
});
+
+describe("isTileUrlTemplate", () => {
+ it("accepts an http(s) URL naming the tile by z/x/y or by quadkey", () => {
+ expect(isTileUrlTemplate(TILE_URL)).toBe(true);
+ expect(isTileUrlTemplate("http://tiles.example.org/{quadkey}.jpeg")).toBe(true);
+ expect(isTileUrlTemplate("https://tiles.example.org/{z}/{x}.png")).toBe(false);
+ expect(isTileUrlTemplate("ftp://tiles.example.org/{z}/{x}/{y}.png")).toBe(false);
+ expect(isTileUrlTemplate("versatiles-colorful")).toBe(false);
+ });
+});
diff --git a/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsx b/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsx
index 31aaf623e5..e93b5c8610 100644
--- a/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsx
+++ b/apps/client/src/widgets/collections/geomap/GeoMapProperties.tsx
@@ -18,6 +18,7 @@ import { useNoteLabel, useNoteLabelBoolean, useNoteRelation } from "../../react/
import NoteAutocomplete from "../../react/NoteAutocomplete";
import { type BookProperty, ViewPropertySection } from "../../react/NotePropertyMenu";
import SegmentedChoice from "../../react/SegmentedChoice";
+import { DEFAULT_MAP_LAYER_NAME, isTileUrl } from "./map_layer";
import { formatImageExtent, type ImageSize, parseImageExtent } from "./space";
/** What the map knows of its image: none, loading, unusable, or loaded at its natural size. */
@@ -26,8 +27,8 @@ export type GeoMapImageState =
| { status: "error"; reason: "unloadable" | "svg" }
| { status: "image"; size: ImageSize };
-/** What a geo map is drawn over: a world map in one of its styles, or an image note. */
-type BackgroundKind = "map" | "image";
+/** What a geo map is drawn over: a built-in world map, a raster tileset, or an image note. */
+type BackgroundKind = "map" | "tiles" | "image";
interface BackgroundOption {
value: BackgroundKind;
@@ -92,36 +93,50 @@ function isMapStyle(property: BookProperty) {
}
/**
- * A world map with its style, or an image with its coordinates.
+ * A built-in world map with its style, a tileset with its URL, or an image with its coordinates.
*
- * Going back to a world map disables `~map:image` as `~disabled:map:image` rather than removing it,
- * and choosing the image enables it again. Without a disabled image, choosing the image writes
- * nothing until an image note is picked, so the map stays drawn as it was until then. An inherited
- * image can only be disabled on the note that owns it.
+ * Leaving the image disables `~map:image` as `~disabled:map:image` rather than removing it, and
+ * going back to a built-in style disables a tileset's `#map:style` the same way; choosing either
+ * again enables it. Without a disabled one, choosing the image or a tileset writes nothing until an
+ * image note is picked or a URL is entered, so the map stays drawn as it was until then. An
+ * inherited image can only be disabled on the note that owns it.
*/
function BackgroundCard({ note, image }: { note: FNote; image: GeoMapImageState }) {
const [ imageNoteId, setImageNoteId ] = useNoteRelation(note, "map:image");
- // Read so that the card follows the relation being disabled and enabled.
+ const [ style, setStyle ] = useNoteLabel(note, "map:style");
+ // Read so that the card follows the image and the tileset being disabled and enabled.
useNoteRelation(note, "disabled:map:image");
- const [ kind, setKind ] = useState<BackgroundKind>(imageNoteId ? "image" : "map");
+ useNoteLabel(note, "disabled:map:style");
+ const tileUrl = isTileUrl(style) ? style : undefined;
+ const savedKind: BackgroundKind = imageNoteId ? "image" : tileUrl ? "tiles" : "map";
+ const [ kind, setKind ] = useState<BackgroundKind>(savedKind);
const isInherited = !!imageNoteId && !note.getOwnedRelation("map:image");
const inheritedReason = isInherited ? t("geo-map.background-image-inherited") : undefined;
const options = BACKGROUND_OPTIONS.map((option) =>
- option.value === "map" ? { ...option, unavailable: inheritedReason } : option);
+ option.value !== "image" ? { ...option, unavailable: inheritedReason } : option);
useEffect(() => {
- if (imageNoteId) setKind("image");
- }, [ imageNoteId ]);
+ if (savedKind !== "map") setKind(savedKind);
+ }, [ savedKind ]);
function changeKind(newKind: BackgroundKind) {
setKind(newKind);
- const ownsImage = !!note.getOwnedRelation("map:image");
- const ownsDisabledImage = !!note.getOwnedRelation("disabled:map:image");
- if (newKind === "map" && ownsImage) {
+ if (newKind !== "image" && note.getOwnedRelation("map:image")) {
void attributes.toggleDangerousAttribute(note, "relation", "map:image", false);
- } else if (newKind === "image" && !imageNoteId && ownsDisabledImage) {
+ } else if (newKind === "image" && !imageNoteId && note.getOwnedRelation("disabled:map:image")) {
void attributes.toggleDangerousAttribute(note, "relation", "map:image", true);
}
+
+ if (newKind === "map" && tileUrl) {
+ if (note.getOwnedLabel("map:style")) {
+ void attributes.toggleDangerousAttribute(note, "label", "map:style", false);
+ } else {
+ // An inherited tileset is overridden, since only its owner can disable it.
+ setStyle(DEFAULT_MAP_LAYER_NAME);
+ }
+ } else if (newKind === "tiles" && !tileUrl && note.getOwnedLabel("disabled:map:style")) {
+ void attributes.toggleDangerousAttribute(note, "label", "map:style", true);
+ }
}
function pickImage(noteId: string) {
@@ -132,6 +147,13 @@ function BackgroundCard({ note, image }: { note: FNote; image: GeoMapImageState
}
}
+ function setTileUrl(url: string) {
+ setStyle(url);
+ if (note.getOwnedLabel("disabled:map:style")) {
+ void attributes.removeOwnedLabelByName(note, "disabled:map:style");
+ }
+ }
+
return (
<Card className="geo-map-properties-background" heading={t("geo-map.background")}>
<OptionCardSection
@@ -155,6 +177,10 @@ function BackgroundCard({ note, image }: { note: FNote; image: GeoMapImageState
<ViewPropertySection note={note} property={MAP_STYLE_PROPERTY} />
)}
+ {kind === "tiles" && (
+ <TileSettings note={note} tileUrl={tileUrl} onChangeUrl={setTileUrl} />
+ )}
+
{kind === "image" && (
<ImageSettings
note={note}
@@ -174,6 +200,12 @@ const BACKGROUND_OPTIONS: BackgroundOption[] = [
description: t("geo-map.background-map-description"),
icon: "bx bx-world"
},
+ {
+ value: "tiles",
+ title: t("geo-map.background-tiles"),
+ description: t("geo-map.background-tiles-description"),
+ icon: "bx bx-grid-alt"
+ },
{
value: "image",
title: t("geo-map.background-image"),
@@ -182,6 +214,76 @@ const BACKGROUND_OPTIONS: BackgroundOption[] = [
}
];
+/** A tileset's URL, committed when the box is left, and whether its tiles are dark. */
+function TileSettings({ note, tileUrl, onChangeUrl }: {
+ note: FNote;
+ tileUrl: string | undefined;
+ onChangeUrl: (url: string) => void;
+}) {
+ const [ isDarkTiles, setDarkTiles ] = useNoteLabelBoolean(note, "map:darkStyle");
+ const [ draft, setDraft ] = useState(tileUrl ?? "");
+ const [ isInvalid, setInvalid ] = useState(false);
+
+ useEffect(() => {
+ setDraft(tileUrl ?? "");
+ setInvalid(false);
+ }, [ tileUrl ]);
+
+ function commit(value: string) {
+ const url = value.trim();
+ if (!url || url === tileUrl) {
+ setInvalid(false);
+ return;
+ }
+
+ const isValid = isTileUrlTemplate(url);
+ setInvalid(!isValid);
+ if (isValid) onChangeUrl(url);
+ }
+
+ return <>
+ <OptionCardSection
+ label={t("geo-map.tiles-url")}
+ description={t("geo-map.tiles-url-description")}
+ stacked
+ >
+ <FormTextBox
+ className="geo-map-tiles-url"
+ type="url"
+ placeholder={TILE_URL_PLACEHOLDER}
+ currentValue={draft}
+ onChange={setDraft}
+ onBlur={commit}
+ />
+ </OptionCardSection>
+
+ {isInvalid && (
+ <CardSection>
+ <Admonition type="caution" className="geo-map-tiles-url-error">
+ {t("geo-map.tiles-url-invalid")}
+ </Admonition>
+ </CardSection>
+ )}
+
+ <OptionCardSection
+ name="geo-map-dark-tiles"
+ label={t("geo-map.dark-tiles")}
+ description={t("geo-map.dark-tiles-description")}
+ >
+ <FormToggle currentValue={isDarkTiles} onChange={setDarkTiles} />
+ </OptionCardSection>
+ </>;
+}
+
+const TILE_URL_PLACEHOLDER = "https://tile.example.org/{z}/{x}/{y}.png";
+
+/** Whether a URL can serve tiles: an `http(s)` address naming the tile by `{z}/{x}/{y}` or `{quadkey}`. */
+export function isTileUrlTemplate(url: string) {
+ if (!isTileUrl(url)) return false;
+ return url.includes("{quadkey}")
+ || [ "{z}", "{x}", "{y}" ].every((placeholder) => url.includes(placeholder));
+}
+
function ImageSettings({ note, image, imageNoteId, onPickImage }: {
note: FNote;
image: GeoMapImageState;
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index c23354ecd6..4f4b68f0bf 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -32,7 +32,7 @@ import ImageRulers from "./ImageRulers";
import { GPX_MIME, GpxTrack } from "./GpxTrack";
import type { GeoSearchResult } from "./geocoding";
import Map, { type CameraLimits, DEFAULT_ZOOM, GeoMouseEvent } from "./map";
-import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS, MapLayer } from "./map_layer";
+import { DEFAULT_MAP_LAYER_NAME, isTileUrl, MAP_LAYERS, MapLayer } from "./map_layer";
import MapToolbar from "./MapToolbar";
import Markers, { DEFAULT_MARKER_COLOR, FitToNotes } from "./Markers";
import PlaceMarker from "./PlaceMarker";
@@ -702,7 +702,7 @@ function useLayerData(note: FNote, image: { url: string; space: ImageSpace } | u
}
// Custom layers.
- if (layerName?.startsWith("http")) {
+ if (isTileUrl(layerName)) {
return {
name: "Custom",
type: "raster",
diff --git a/apps/client/src/widgets/collections/geomap/map_layer.ts b/apps/client/src/widgets/collections/geomap/map_layer.ts
index b79531749d..d887046b20 100644
--- a/apps/client/src/widgets/collections/geomap/map_layer.ts
+++ b/apps/client/src/widgets/collections/geomap/map_layer.ts
@@ -90,6 +90,11 @@ export const MAP_LAYERS: Record<string, MapLayer> = {
export const DEFAULT_MAP_LAYER_NAME: keyof typeof MAP_LAYERS = "versatile-colorful-eclipse";
+/** Whether a `#map:style` value is the URL of a raster tileset rather than a built-in style's name. */
+export function isTileUrl(style: string | null | undefined): style is string {
+ return !!style && /^https?:\/\//i.test(style);
+}
+
/**
* One of the styles VersaTiles publishes, labelled in English.
*
diff --git a/apps/client/src/widgets/note_bars/collection-properties-config.tsx b/apps/client/src/widgets/note_bars/collection-properties-config.tsx
index a3e0551dcd..2ad5ee4926 100644
--- a/apps/client/src/widgets/note_bars/collection-properties-config.tsx
+++ b/apps/client/src/widgets/note_bars/collection-properties-config.tsx
@@ -3,7 +3,7 @@ import { t } from "i18next";
import Component from "../../components/component";
import FNote from "../../entities/fnote";
import attributes from "../../services/attributes";
-import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS, type MapLayer } from "../collections/geomap/map_layer";
+import { DEFAULT_MAP_LAYER_NAME, isTileUrl, MAP_LAYERS, type MapLayer } from "../collections/geomap/map_layer";
import { ViewTypeOptions } from "../collections/interface";
import { DEFAULT_THEME, getPresentationThemes } from "../collections/presentation/themes";
import { FormDropdownDivider, FormListItem } from "../react/FormList";
@@ -100,8 +100,9 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {
type: "combobox",
bindToLabel: "map:style",
defaultValue: DEFAULT_MAP_LAYER_NAME,
- // An image map is drawn over its image instead.
- isVisible: (note) => !note.getRelationValue("map:image"),
+ // An image map is drawn over its image, and a tileset map over its tiles.
+ isVisible: (note) => !note.getRelationValue("map:image")
+ && !isTileUrl(note.getLabelValue("map:style")),
options: [
{
title: t("book_properties_config.raster"),
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 51bdbe3203..db798f4418 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
@@ -545,17 +545,34 @@ class="admonition note">
<h3>Custom map style / tiles</h3>
<p>Starting with v0.102.0 it is possible to use custom tile sets, but only
in raster format.</p>
-<p>To do so, manually set the <code>#map:style</code> <a href="#root/_help_HI6GBBIduIgv">label</a> to
- the URL of the tile set. For example, to use Esri.NatGeoWorldMap, set the
- value to <a href="https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/%7Bz%7D/%7By%7D/%7Bx%7D."><code>https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}</code>.</a>
-</p>
+<p>To use one:</p>
+<ol>
+ <li>Open the <em>Geo map properties</em> dialog from the <a class="reference-link"
+ href="#root/_help_8YBEPzcpUgxw">Note menu</a>.</li>
+ <li>Under <em>Background</em>, set <em>Type</em> to <em>Custom tileset</em>.</li>
+ <li>In <em>Tile URL</em>, enter the address of the tile set, with <code>{z}</code>, <code>{x}</code> and <code>{y}</code> where
+ the zoom level and the position of the tile go. For example, to use Esri.NatGeoWorldMap,
+ enter <a href="https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/%7Bz%7D/%7By%7D/%7Bx%7D"><code>https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}</code></a>.
+ The URL is saved once you leave the field; a URL that doesn't start with <code>http://</code> or <code>https://</code>,
+ or that lacks one of the three placeholders, is not saved.</li>
+ <li>If the tiles are dark, turn on <em>Dark tileset</em>, which draws the marker
+ titles in a light color so that they remain readable.</li>
+</ol>
<p>Additionally:</p>
<ul>
<li>Hi-DPI tiles are supported via the <code>{r}</code> placeholder.</li>
- <li>To mark the custom style as dark (which affects the styling of the UI),
- apply the <code>map:darkStyle</code> label. This attribute also overrides
- builtin themes.</li>
+ <li>Servers that number their tiles by quadkey are supported via the <code>{quadkey}</code> placeholder,
+ in place of <code>{z}</code>, <code>{x}</code> and <code>{y}</code>.</li>
</ul>
+<p>To go back to a built-in style, set <em>Type</em> back to <em>Vector &amp; Raster</em>.
+ The tile set is switched off rather than removed: its label is renamed
+ to <code>#disabled:map:style</code>, so setting <em>Type</em> to <em>Custom tileset</em> again
+ brings back the same URL. A tile set inherited from a parent note or a
+ template is overridden by the default style instead.</p>
+<p>The tile set can also be set manually: the URL goes in the <code>#map:style</code> <a
+ href="#root/_help_HI6GBBIduIgv">label</a>, and the <code>#map:darkStyle</code> label
+ marks it as dark. <code>#map:darkStyle</code> also overrides the built-in
+ styles.</p>
<aside class="admonition note">
<p>For a list of tile sets, see the <a href="https://leaflet-extras.github.io/leaflet-providers/preview/">Leaflet Providers preview</a> page.
Select a desired tile set and just copy the URL from the <em>Plain JavaScript</em> example.</p>
@@ -593,7 +610,8 @@ class="admonition note">
from the settings menu of the&nbsp;<a class="reference-link" href="#root/_help_CssoWBu8I7jF">Collection Properties</a>.
Its <em>Included notes</em> section sets whether archived notes are shown
and the <em>Maximum nesting depth</em> (see below), and its <em>Background</em> section
- holds the map style, or, with <em>Type</em> set to <em>Custom image</em>,
+ holds the map style, the URL of a custom tile set when <em>Type</em> is set
+ to <em>Custom tileset</em> (see above), or, with <em>Type</em> set to <em>Custom image</em>,
draws the map over an image of your own instead, as described in&nbsp;<a
class="reference-link" href="#root/_help_ZRDXGc0nAIh4">Image maps</a>.</p>
<p>The map shows the notes of its whole subtree, not only its children. <em>Maximum nesting depth</em> (<code>#maxNestingDepth</code>)
diff --git a/docs/User Guide/User Guide/Collections/Geo Map.md b/docs/User Guide/User Guide/Collections/Geo Map.md
index 0bbaa242a4..661187f734 100644
--- a/docs/User Guide/User Guide/Collections/Geo Map.md
+++ b/docs/User Guide/User Guide/Collections/Geo Map.md
@@ -372,12 +372,21 @@ The buildings will only appear from zoom 14 onwards to avoid lag.
Starting with v0.102.0 it is possible to use custom tile sets, but only in raster format.
-To do so, manually set the `#map:style` [label](../Advanced%20Usage/Attributes/Labels.md) to the URL of the tile set. For example, to use Esri.NatGeoWorldMap, set the value to [`https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}`.](https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/%7Bz%7D/%7By%7D/%7Bx%7D.)
+To use one:
+
+1. Open the _Geo map properties_ dialog from the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20menu.md">Note menu</a>.
+2. Under _Background_, set _Type_ to _Custom tileset_.
+3. In _Tile URL_, enter the address of the tile set, with `{z}`, `{x}` and `{y}` where the zoom level and the position of the tile go. For example, to use Esri.NatGeoWorldMap, enter [`https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}`](https://server.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/%7Bz%7D/%7By%7D/%7Bx%7D). The URL is saved once you leave the field; a URL that doesn't start with `http://` or `https://`, or that lacks one of the three placeholders, is not saved.
+4. If the tiles are dark, turn on _Dark tileset_, which draws the marker titles in a light color so that they remain readable.
Additionally:
* Hi-DPI tiles are supported via the `{r}` placeholder.
-* To mark the custom style as dark (which affects the styling of the UI), apply the `map:darkStyle` label. This attribute also overrides builtin themes.
+* Servers that number their tiles by quadkey are supported via the `{quadkey}` placeholder, in place of `{z}`, `{x}` and `{y}`.
+
+To go back to a built-in style, set _Type_ back to _Vector & Raster_. The tile set is switched off rather than removed: its label is renamed to `#disabled:map:style`, so setting _Type_ to _Custom tileset_ again brings back the same URL. A tile set inherited from a parent note or a template is overridden by the default style instead.
+
+The tile set can also be set manually: the URL goes in the `#map:style` [label](../Advanced%20Usage/Attributes/Labels.md), and the `#map:darkStyle` label marks it as dark. `#map:darkStyle` also overrides the built-in styles.
> [!NOTE]
> For a list of tile sets, see the [Leaflet Providers preview](https://leaflet-extras.github.io/leaflet-providers/preview/) page. Select a desired tile set and just copy the URL from the _Plain JavaScript_ example.
@@ -395,6 +404,6 @@ The following options can be configured either via the <a class="reference-link
* The clusters display the number of items they contain. The color also changes based on the count.
* Clicking on a cluster will automatically zoom in so that the individual markers that make up the cluster are now visible.
-The same options are also listed under _General_ in the <span class="tn-icon bx bx-cog"></span>_Geo map properties_ dialog, opened from the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20menu.md">Note menu</a> or from the settings menu of the <a class="reference-link" href="Collection%20Properties.md">Collection Properties</a>. Its _Included notes_ section sets whether archived notes are shown and the _Maximum nesting depth_ (see below), and its _Background_ section holds the map style, or, with _Type_ set to _Custom image_, draws the map over an image of your own instead, as described in <a class="reference-link" href="Geo%20Map/Image%20maps.md">Image maps</a>.
+The same options are also listed under _General_ in the <span class="tn-icon bx bx-cog"></span>_Geo map properties_ dialog, opened from the <a class="reference-link" href="../Basic%20Concepts%20and%20Features/UI%20Elements/Note%20menu.md">Note menu</a> or from the settings menu of the <a class="reference-link" href="Collection%20Properties.md">Collection Properties</a>. Its _Included notes_ section sets whether archived notes are shown and the _Maximum nesting depth_ (see below), and its _Background_ section holds the map style, the URL of a custom tile set when _Type_ is set to _Custom tileset_ (see above), or, with _Type_ set to _Custom image_, draws the map over an image of your own instead, as described in <a class="reference-link" href="Geo%20Map/Image%20maps.md">Image maps</a>.
The map shows the notes of its whole subtree, not only its children. _Maximum nesting depth_ (`#maxNestingDepth`) limits how deep below the map it looks: `0` shows only the children, `1` adds their children, and so on. Without a value, every level is shown.
\ No newline at end of file
diff --git a/packages/commons/src/lib/builtin_attributes.spec.ts b/packages/commons/src/lib/builtin_attributes.spec.ts
index 20992a3f1d..855490b3d2 100644
--- a/packages/commons/src/lib/builtin_attributes.spec.ts
+++ b/packages/commons/src/lib/builtin_attributes.spec.ts
@@ -67,6 +67,7 @@ describe("derived name types", () => {
const disabledRelation: RelationNames = "disabled:renderNote";
// So do the harmless ones that opt in to being switched off.
const disabledImage: RelationNames = "disabled:map:image";
+ const disabledStyle: LabelNames = "disabled:map:style";
const flag: FilterLabelsByType<boolean> = "archived";
const text: FilterLabelsByType<string> = "searchString";
@@ -79,8 +80,8 @@ describe("derived name types", () => {
const wrongValueType: FilterLabelsByType<string> = "archived";
expect([
- label, relation, disabledLabel, disabledRelation, disabledImage, flag, text, count, unknown,
- wrongValueType
- ]).toHaveLength(10);
+ label, relation, disabledLabel, disabledRelation, disabledImage, disabledStyle, flag, text,
+ count, unknown, wrongValueType
+ ]).toHaveLength(11);
});
});
diff --git a/packages/commons/src/lib/builtin_attributes.ts b/packages/commons/src/lib/builtin_attributes.ts
index 60f5c859dc..c84440d75f 100644
--- a/packages/commons/src/lib/builtin_attributes.ts
+++ b/packages/commons/src/lib/builtin_attributes.ts
@@ -22,6 +22,11 @@ interface BuiltinLabelCommon {
* `disabled:*` members of {@link LabelNames} / {@link RelationNames} come from.
*/
isDangerous?: boolean;
+ /**
+ * Whether the label can be switched off by a `disabled:` prefix, keeping its value, although it
+ * is not dangerous. Gives it a `disabled:*` member of {@link LabelNames}, as a dangerous one has.
+ */
+ canBeDisabled?: boolean;
/**
* Whether the *value* may contain user data, even though the *name* is system-defined. The name of
* such an attribute is safe to keep in an anonymized database dump, its value is not — see
@@ -326,7 +331,9 @@ const BUILTIN_ATTRIBUTES = [
{ type: "label", name: "mapType", valueType: "select", hasUserValue: true, selectOptions: [
"link", "tree"
] },
- { type: "label", name: "map:style", valueType: "text", hasUserValue: true },
+ // A built-in style's name, or the URL of a raster tileset. A tileset is switched off rather than
+ // removed when the map goes back to a built-in style, so its URL is kept for switching back.
+ { type: "label", name: "map:style", valueType: "text", hasUserValue: true, canBeDisabled: 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 },