Skip to content

Commit

Permalink
Add admin layer in basemap
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri authored and samshara committed Jun 27, 2024
1 parent a8ec800 commit ba6734e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-pugs-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"go-web-app": patch
---

Show admin labels in maps in different languages, potentially fixing [##1036](https://github.com/IFRCGo/go-web-app/issues/1036)
35 changes: 33 additions & 2 deletions app/src/components/domain/BaseMap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useMemo } from 'react';
import {
useContext,
useMemo,
} from 'react';
import { LanguageContext } from '@ifrc-go/ui/contexts';
import {
isDefined,
isFalsyString,
Expand All @@ -12,7 +16,6 @@ import { type SymbolLayer } from 'mapbox-gl';

import useCountry from '#hooks/domain/useCountry';
import {
adminLabelLayerOptions,
defaultMapOptions,
defaultMapStyle,
defaultNavControlOptions,
Expand Down Expand Up @@ -98,6 +101,34 @@ function BaseMap(props: Props) {
[countries],
);

const {
currentLanguage,
} = useContext(LanguageContext);

const adminLabelLayerOptions : Omit<SymbolLayer, 'id'> = useMemo(
() => {
// ar, es, fr
let label: string;
if (currentLanguage === 'es') {
label = 'name_es';
} else if (currentLanguage === 'ar') {
label = 'name_ar';
} else if (currentLanguage === 'fr') {
label = 'name_fr';
} else {
label = 'name';
}

return {
type: 'symbol',
layout: {
'text-field': ['get', label],
},
};
},
[currentLanguage],
);

return (
<Map
mapStyle={mapStyle ?? defaultMapStyle}
Expand Down

0 comments on commit ba6734e

Please sign in to comment.