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
feat(geomap): support hiding labels
Elian Dorane6d728715f59
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex f434ffeddd..8609044efa 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2104,7 +2104,8 @@"raster": "Raster","vector_light": "Vector (Light)","vector_dark": "Vector (Dark)",- "show-scale": "Show scale"+ "show-scale": "Show scale",+ "show-labels": "Show marker names"},"table_context_menu": {"delete_row": "Delete row"diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsxindex b22531c727..8be547fa3a 100644--- a/apps/client/src/widgets/collections/geomap/index.tsx+++ b/apps/client/src/widgets/collections/geomap/index.tsx@@ -46,6 +46,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMconst [ coordinates, setCoordinates ] = useState(viewConfig?.view?.center);const [ zoom, setZoom ] = useState(viewConfig?.view?.zoom);const [ hasScale ] = useNoteLabelBoolean(note, "map:scale");+ const [ hideLabels ] = useNoteLabelBoolean(note, "map:hideLabels");const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");const [ notes, setNotes ] = useState<FNote[]>([]);const layerData = useLayerData(note);@@ -162,7 +163,7 @@ export default function GeoView({ note, noteIds, viewConfig, saveConfig }: ViewMonContextMenu={onContextMenu}scale={hasScale}>- {notes.map(note => <NoteWrapper note={note} isReadOnly={isReadOnly} />)}+ {notes.map(note => <NoteWrapper note={note} isReadOnly={isReadOnly} hideLabels={hideLabels} />)}</Map>}<GeoMapTouchBar state={state} map={apiRef.current} /></div>@@ -201,22 +202,26 @@ function ToggleReadOnlyButton({ note }: { note: FNote }) {/>;}-function NoteWrapper({ note, isReadOnly }: { note: FNote, isReadOnly: boolean }) {+function NoteWrapper({ note, isReadOnly, hideLabels }: {+ note: FNote,+ isReadOnly: boolean,+ hideLabels: boolean+}) {const mime = useNoteProperty(note, "mime");const [ location ] = useNoteLabel(note, LOCATION_ATTRIBUTE);if (mime === "application/gpx+xml") {- return <NoteGpxTrack note={note} />;+ return <NoteGpxTrack note={note} hideLabels={hideLabels} />;}if (location) {const latLng = location?.split(",", 2).map((el) => parseFloat(el)) as [ number, number ] | undefined;if (!latLng) return;- return <NoteMarker note={note} editable={!isReadOnly} latLng={latLng} />;+ return <NoteMarker note={note} editable={!isReadOnly} latLng={latLng} hideLabels={hideLabels} />;}}-function NoteMarker({ note, editable, latLng }: { note: FNote, editable: boolean, latLng: [number, number] }) {+function NoteMarker({ note, editable, latLng, hideLabels }: { note: FNote, editable: boolean, latLng: [number, number], hideLabels: boolean }) {// React to changesconst [ color ] = useNoteLabel(note, "color");const [ iconClass ] = useNoteLabel(note, "iconClass");@@ -224,8 +229,9 @@ function NoteMarker({ note, editable, latLng }: { note: FNote, editable: booleanconst title = useNoteProperty(note, "title");const icon = useMemo(() => {- return buildIcon(note.getIcon(), note.getColorClass() ?? undefined, title, note.noteId, archived);- }, [ iconClass, color, title, note.noteId, archived]);+ const titleOrNone = hideLabels ? undefined : title;+ return buildIcon(note.getIcon(), note.getColorClass() ?? undefined, titleOrNone, note.noteId, archived);+ }, [ iconClass, color, title, note.noteId, archived, hideLabels ]);const onClick = useCallback(() => {appContext.triggerCommand("openInPopup", { noteIdOrPath: note.noteId });@@ -257,7 +263,7 @@ function NoteMarker({ note, editable, latLng }: { note: FNote, editable: boolean/>;}-function NoteGpxTrack({ note }: { note: FNote }) {+function NoteGpxTrack({ note, hideLabels }: { note: FNote, hideLabels?: boolean }) {const [ xmlString, setXmlString ] = useState<string>();const blob = useNoteBlob(note);@@ -278,7 +284,7 @@ function NoteGpxTrack({ note }: { note: FNote }) {const options = useMemo<GPXOptions>(() => ({markers: {- startIcon: buildIcon(note.getIcon(), note.getColorClass(), note.title),+ startIcon: buildIcon(note.getIcon(), note.getColorClass(), hideLabels ? undefined : note.title),endIcon: buildIcon("bxs-flag-checkered"),wptIcons: {"": buildIcon("bx bx-pin")@@ -287,7 +293,7 @@ function NoteGpxTrack({ note }: { note: FNote }) {polyline_options: {color: note.getLabelValue("color") ?? "blue"}- }), [ color, iconClass ]);+ }), [ color, iconClass, hideLabels ]);return xmlString && <GpxTrack gpxXmlString={xmlString} options={options} />;}diff --git a/apps/client/src/widgets/note_bars/CollectionProperties.tsx b/apps/client/src/widgets/note_bars/CollectionProperties.tsxindex 5dba675e6d..7f739e34bb 100644--- a/apps/client/src/widgets/note_bars/CollectionProperties.tsx+++ b/apps/client/src/widgets/note_bars/CollectionProperties.tsx@@ -226,8 +226,8 @@ function CheckBoxPropertyView({ note, property }: { note: FNote, property: Check<FormListToggleableItemicon={property.icon}title={property.label}- currentValue={value}- onChange={setValue}+ currentValue={ property.reverseValue ? !value : value }+ onChange={newValue => setValue(property.reverseValue ? !newValue : newValue)}/>);}diff --git a/apps/client/src/widgets/ribbon/collection-properties-config.tsx b/apps/client/src/widgets/ribbon/collection-properties-config.tsxindex 1f79217e9c..17bdff5052 100644--- a/apps/client/src/widgets/ribbon/collection-properties-config.tsx+++ b/apps/client/src/widgets/ribbon/collection-properties-config.tsx@@ -20,6 +20,8 @@ export interface CheckBoxProperty {label: string;bindToLabel: FilterLabelsByType<boolean>;icon?: string;+ /** When true, the checkbox will be checked when the label value is false. Useful when the label represents a "hide" action, without exposing double negatives to the user. */+ reverseValue?: boolean;}export interface ButtonProperty {@@ -156,6 +158,13 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {icon: "bx bx-ruler",type: "checkbox",bindToLabel: "map:scale"+ },+ {+ label: t("book_properties_config.show-labels"),+ icon: "bx bx-label",+ type: "checkbox",+ bindToLabel: "map:hideLabels",+ reverseValue: true}]},diff --git a/packages/commons/src/lib/attribute_names.ts b/packages/commons/src/lib/attribute_names.tsindex b524b409f0..a73f97d30f 100644--- a/packages/commons/src/lib/attribute_names.ts+++ b/packages/commons/src/lib/attribute_names.ts@@ -48,6 +48,7 @@ type Labels = {"calendar:initialDate": string;"map:style": string;"map:scale": boolean;+ "map:hideLabels": boolean;"board:groupBy": string;maxNestingDepth: number;includeArchived: boolean;