From 7c1e075b9fb3e26cbcf27cea16b0e3931e355208 Mon Sep 17 00:00:00 2001 From: Matthieu Viry Date: Thu, 3 Oct 2024 08:56:12 +0200 Subject: [PATCH] Allow the user to choose the text anchor for labels --- src/components/Modals/LayerSettings.tsx | 39 +++++++++++++++++++++++++ src/global.d.ts | 2 +- src/i18n/en/index.ts | 4 +++ src/i18n/fr/index.ts | 4 +++ src/i18n/i18n-types.ts | 32 ++++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/components/Modals/LayerSettings.tsx b/src/components/Modals/LayerSettings.tsx index 5dba5067..cf23d53f 100644 --- a/src/components/Modals/LayerSettings.tsx +++ b/src/components/Modals/LayerSettings.tsx @@ -187,6 +187,22 @@ function makeSettingsLabels( const rendererParameters = props.rendererParameters as LabelsParameters; const isProportional = !!props.rendererParameters.proportional; + const redrawLabels = () => { + // We redraw the labels by toggling the visibility of the layer + setLayersDescriptionStoreBase( + produce((draft: LayersDescriptionStoreType) => { + const layer = draft.layers.find((l) => l.id === props.id) as LayerDescriptionLabels; + layer.visible = false; + }), + ); + setLayersDescriptionStoreBase( + produce((draft: LayersDescriptionStoreType) => { + const layer = draft.layers.find((l) => l.id === props.id) as LayerDescriptionLabels; + layer.visible = true; + }), + ); + }; + return <> + { + updateProp(props.id, ['rendererParameters', 'default', 'textAnchor'], v); + // Update the textAnchor properties for each "specific" parameters + setLayersDescriptionStoreBase( + produce((draft: LayersDescriptionStoreType) => { + const layer = draft.layers.find((l) => l.id === props.id) as LayerDescriptionLabels; + Object.keys((layer.rendererParameters as LabelsParameters).specific).forEach((k) => { + // eslint-disable-next-line no-param-reassign + layer.rendererParameters.specific[+k].textAnchor = v as 'start' | 'middle' | 'end'; + }); + }), + ); + }} + > + + + + LocalizedString + /** + * Text anchor + */ + TextAnchor: () => LocalizedString + /** + * Start + */ + TextAnchorStart: () => LocalizedString + /** + * Middle + */ + TextAnchorMiddle: () => LocalizedString + /** + * End + */ + TextAnchorEnd: () => LocalizedString /** * Font style */