Skip to content

Build your personal knowledge base with Trilium Notes

feat(collections/map): use SVG for markers

Elian Doran3865d96d4466
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index 2daf49d5b5..fd2ae6dfae 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -178,6 +178,12 @@ function useMarkerData(note: FNote | null | undefined, apiRef: RefObject<maplibr
const map = apiRef.current as maplibregl.Map | undefined;
if (!map) return;
+ svgToImage(MARKER_SVG, (img) => {
+ map.addImage("custom-marker", img, {
+ pixelRatio: window.devicePixelRatio
+ });
+ });
+
const features: maplibregl.GeoJSONFeature[] = [];
for (const childNote of childNotes) {
const location = childNote.getLabelValue(LOCATION_ATTRIBUTE);
@@ -207,11 +213,13 @@ function useMarkerData(note: FNote | null | undefined, apiRef: RefObject<maplibr
});
map.addLayer({
id: "points-layer",
- type: "circle",
+ type: "symbol",
source: "points",
- paint: {
- "circle-radius": 6,
- "circle-color": "#ff0000"
+ layout: {
+ "icon-image": "custom-marker",
+ "icon-size": 1,
+ "icon-anchor": "bottom",
+ "icon-allow-overlap": true
}
});
@@ -222,6 +230,21 @@ function useMarkerData(note: FNote | null | undefined, apiRef: RefObject<maplibr
}, [ apiRef, childNotes ]);
}
+function svgToImage(svgString, callback) {
+ const svgBlob = new Blob([svgString], { type: "image/svg+xml" });
+ const url = URL.createObjectURL(svgBlob);
+
+ const img = new Image();
+
+ img.onload = () => {
+ URL.revokeObjectURL(url);
+ callback(img);
+ };
+
+ img.src = url;
+}
+
+
function useLayerData(note: FNote) {
const [ layerName ] = useNoteLabel(note, "map:style");
// Memo is needed because it would generate unnecessary reloads due to layer change.