Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(geomap): say so when an image map is pointed at an SVG
Elian Dorane8a0f9cea75a
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex d042c19c11..60316588a0 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3084,6 +3084,7 @@"unable-to-load-map": "Unable to load map.","webgl-unavailable": "This map can't be drawn because WebGL isn't available. Check that hardware acceleration is enabled and that your graphics drivers are up to date.","image-unavailable": "This map's image couldn't be loaded. Check that the note its map:image relation points to is an image.",+ "image-svg-unsupported": "SVG images can't be used as a map. Convert the image to PNG, JPEG or WebP instead.","enter-3d": "Tilt into a 3D view\nHold Ctrl and drag to tilt the map freely","exit-3d": "Lay the map flat again","close-details": "Close",diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex 056eac8393..5bdcd9fa85 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -412,7 +412,10 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMlives on the map itself (see EditToolbar), where it survives the map goingfullscreen without this bar. */}<CollectionProperties note={note} />- {imageMap.status === "error" && <NoItems icon="bx bx-image-alt" text={t("geo-map.image-unavailable")} />}+ {imageMap.status === "error" && <NoItems+ icon="bx bx-image-alt"+ text={t(imageMap.reason === "svg" ? "geo-map.image-svg-unsupported" : "geo-map.image-unavailable")}+ />}{ coordinates !== undefined && zoom !== undefined && imageMap.status !== "loading" && imageMap.status !== "error" &&<MapSpaceContext.Provider value={space}><Map// Built afresh when the image changes: the camera's limits are fixed when the map@@ -539,7 +542,7 @@ function pickGpxFile(): Promise<File | null> {type ImageMapState =| { status: "geo" }| { status: "loading" }- | { status: "error" }+ | { status: "error"; reason: "unloadable" | "svg" }| { status: "image"; url: string; space: ImageSpace };function useImageMap(note: FNote): ImageMapState {@@ -558,6 +561,13 @@ function useImageMap(note: FNote): ImageMapState {(async () => {const imageNote = await froca.getNote(imageNoteId, true);+ // MapLibre decodes an image source with `createImageBitmap`, which refuses SVG, and+ // would leave the map blank with only a console warning to show for it.+ if (imageNote?.mime === "image/svg+xml") {+ if (!cancelled) setImage({ status: "error", reason: "svg" });+ return;+ }+// Absolute, as MapLibre resolves a source's URL against its worker rather than the page.const url = imageNote && new URL(`api/images/${imageNote.noteId}/${encodeURIComponent(imageNote.title)}`, document.baseURI).href;@@ -566,7 +576,7 @@ function useImageMap(note: FNote): ImageMapState {if (!url || !size) {logError(`The image ${imageNoteId} of map ${note.noteId} could not be loaded.`);- setImage({ status: "error" });+ setImage({ status: "error", reason: "unloadable" });return;}setImage({ status: "image", url, size });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.htmlindex 8d8734cdaf..fc50e9a035 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@@ -7,7 +7,8 @@<h2>Creating an image map</h2><ol><li>Upload the image as a note of its own, for example by dragging the file- into the note tree.</li>+ into the note tree. PNG, JPEG, WebP and GIF images are supported; SVG images+ are not.</li><li>Create a geo map, or open an existing one.</li><li>In the attributes of the geo map, add a <code>~map:image</code> <a href="#root/_help_Cq5X6iKQop6R">relation</a> pointingto the image note.</li>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.mdindex 94a73ea223..c27f3ac182 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@@ -3,7 +3,7 @@ An image map is a geo map drawn over an image of your own instead of a world map## Creating an image map-1. Upload the image as a note of its own, for example by dragging the file into the note tree.+1. Upload the image as a note of its own, for example by dragging the file into the note tree. PNG, JPEG, WebP and GIF images are supported; SVG images are not.2. Create a geo map, or open an existing one.3. In the attributes of the geo map, add a `~map:image` [relation](../../Advanced%20Usage/Attributes/Relations.md) pointing to the image note.