Skip to content

Commit 762a518

Browse files
authored
Merge pull request #1209 from IFRCGo/add/basemap-admin-layer
Add admin layer in basemap
2 parents a8ec800 + ba6734e commit 762a518

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

.changeset/new-pugs-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"go-web-app": patch
3+
---
4+
5+
Show admin labels in maps in different languages, potentially fixing [##1036](https://github.com/IFRCGo/go-web-app/issues/1036)

app/src/components/domain/BaseMap/index.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { useMemo } from 'react';
1+
import {
2+
useContext,
3+
useMemo,
4+
} from 'react';
5+
import { LanguageContext } from '@ifrc-go/ui/contexts';
26
import {
37
isDefined,
48
isFalsyString,
@@ -12,7 +16,6 @@ import { type SymbolLayer } from 'mapbox-gl';
1216

1317
import useCountry from '#hooks/domain/useCountry';
1418
import {
15-
adminLabelLayerOptions,
1619
defaultMapOptions,
1720
defaultMapStyle,
1821
defaultNavControlOptions,
@@ -98,6 +101,34 @@ function BaseMap(props: Props) {
98101
[countries],
99102
);
100103

104+
const {
105+
currentLanguage,
106+
} = useContext(LanguageContext);
107+
108+
const adminLabelLayerOptions : Omit<SymbolLayer, 'id'> = useMemo(
109+
() => {
110+
// ar, es, fr
111+
let label: string;
112+
if (currentLanguage === 'es') {
113+
label = 'name_es';
114+
} else if (currentLanguage === 'ar') {
115+
label = 'name_ar';
116+
} else if (currentLanguage === 'fr') {
117+
label = 'name_fr';
118+
} else {
119+
label = 'name';
120+
}
121+
122+
return {
123+
type: 'symbol',
124+
layout: {
125+
'text-field': ['get', label],
126+
},
127+
};
128+
},
129+
[currentLanguage],
130+
);
131+
101132
return (
102133
<Map
103134
mapStyle={mapStyle ?? defaultMapStyle}

0 commit comments

Comments
 (0)