Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin layer in basemap #1209

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading