Skip to content

Commit 9f63f03

Browse files
authored
Merge pull request #1564 from IFRCGo/fix/disputed-boundary-map-styling
Fix disputed boundary map styling
2 parents efd1d1a + 3a3fb4a commit 9f63f03

File tree

5 files changed

+267
-92
lines changed

5 files changed

+267
-92
lines changed

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

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ import {
3232
MapLayer,
3333
MapSource,
3434
} from '@togglecorp/re-map';
35-
import type { LngLatBoundsLike } from 'mapbox-gl';
35+
import { type LngLatBoundsLike } from 'mapbox-gl';
3636

37-
import BaseMap from '#components/domain/BaseMap';
3837
import DisasterTypeSelectInput from '#components/domain/DisasterTypeSelectInput';
3938
import DistrictSearchMultiSelectInput, { type DistrictItem } from '#components/domain/DistrictSearchMultiSelectInput';
4039
import Link from '#components/Link';
@@ -48,13 +47,13 @@ import {
4847
DEFAULT_MAP_PADDING,
4948
DURATION_MAP_ZOOM,
5049
} from '#utils/constants';
51-
import { adminFillLayerOptions } from '#utils/map';
5250
import type {
5351
GoApiResponse,
5452
GoApiUrlQuery,
5553
} from '#utils/restRequest';
5654
import { useRequest } from '#utils/restRequest';
5755

56+
import GlobalMap, { type AdminZeroFeatureProperties } from '../GlobalMap';
5857
import {
5958
APPEAL_TYPE_DREF,
6059
APPEAL_TYPE_EAP,
@@ -87,24 +86,8 @@ const sourceOptions: mapboxgl.GeoJSONSourceRaw = {
8786
type: 'geojson',
8887
};
8988

90-
interface CountryProperties {
91-
country_id: number;
92-
disputed: boolean;
93-
fdrs: string;
94-
independent: boolean;
95-
is_deprecated: boolean;
96-
iso: string;
97-
iso3: string;
98-
name: string;
99-
name_ar: string;
100-
name_es: string;
101-
name_fr: string;
102-
record_type: number;
103-
region_id: number;
104-
}
105-
10689
interface ClickedPoint {
107-
feature: GeoJSON.Feature<GeoJSON.Point, CountryProperties>;
90+
featureProperties: AdminZeroFeatureProperties;
10891
lngLat: mapboxgl.LngLatLike;
10992
}
11093

@@ -188,8 +171,8 @@ function ActiveOperationMap(props: Props) {
188171
);
189172

190173
const [
191-
clickedPointProperties,
192-
setClickedPointProperties,
174+
clickedPoint,
175+
setClickedPoint,
193176
] = useState<ClickedPoint| undefined>();
194177

195178
const [scaleBy, setScaleBy] = useInputState<ScaleOption['value']>('peopleTargeted');
@@ -348,29 +331,30 @@ function ActiveOperationMap(props: Props) {
348331
);
349332

350333
const handleCountryClick = useCallback((
351-
feature: mapboxgl.MapboxGeoJSONFeature,
334+
featureProperties: AdminZeroFeatureProperties,
352335
lngLat: mapboxgl.LngLatLike,
353336
) => {
354-
setClickedPointProperties({
355-
feature: feature as unknown as ClickedPoint['feature'],
337+
setClickedPoint({
338+
featureProperties,
356339
lngLat,
357340
});
358-
return false;
341+
342+
return true;
359343
}, []);
360344

361345
const handlePointClose = useCallback(
362346
() => {
363-
setClickedPointProperties(undefined);
347+
setClickedPoint(undefined);
364348
},
365-
[setClickedPointProperties],
349+
[setClickedPoint],
366350
);
367351

368352
const handleClearFiltersButtonclick = useCallback(() => {
369353
setFilter({});
370354
}, [setFilter]);
371355

372-
const popupDetails = clickedPointProperties
373-
? countryGroupedAppeal[clickedPointProperties.feature.properties.iso3]
356+
const popupDetails = clickedPoint
357+
? countryGroupedAppeal[clickedPoint.featureProperties.iso3]
374358
: undefined;
375359

376360
const [districtOptions, setDistrictOptions] = useState<DistrictItem[] | null | undefined>();
@@ -447,15 +431,8 @@ function ActiveOperationMap(props: Props) {
447431
</Link>
448432
)}
449433
>
450-
<BaseMap
451-
baseLayers={(
452-
<MapLayer
453-
layerKey="admin-0"
454-
hoverable
455-
layerOptions={adminFillLayerOptions}
456-
onClick={handleCountryClick}
457-
/>
458-
)}
434+
<GlobalMap
435+
onClick={handleCountryClick}
459436
>
460437
<MapContainerWithDisclaimer
461438
className={styles.mapContainer}
@@ -503,18 +480,18 @@ function ActiveOperationMap(props: Props) {
503480
}
504481
/>
505482
</MapSource>
506-
{clickedPointProperties?.lngLat && (
483+
{clickedPoint?.lngLat && (
507484
<MapPopup
508485
onCloseButtonClick={handlePointClose}
509-
coordinates={clickedPointProperties.lngLat}
486+
coordinates={clickedPoint.lngLat}
510487
heading={(
511488
<Link
512489
to="countriesLayout"
513490
urlParams={{
514-
countryId: clickedPointProperties.feature.properties.country_id,
491+
countryId: clickedPoint.featureProperties.country_id,
515492
}}
516493
>
517-
{clickedPointProperties.feature.properties.name}
494+
{clickedPoint.featureProperties.name}
518495
</Link>
519496
)}
520497
childrenContainerClassName={styles.popupContent}
@@ -560,7 +537,7 @@ function ActiveOperationMap(props: Props) {
560537
padding={DEFAULT_MAP_PADDING}
561538
/>
562539
)}
563-
</BaseMap>
540+
</GlobalMap>
564541
{onPresentationModeButtonClick && !presentationMode && (
565542
<Button
566543
className={styles.presentationModeButton}

app/src/components/domain/ActiveOperationMap/styles.module.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
}
1111

1212
.map-container {
13-
height: 40rem;
13+
height: min(50rem, 70vh);
14+
min-height: 20rem;
1415
}
1516

1617
.footer {

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

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
useContext,
3-
useMemo,
4-
} from 'react';
5-
import { LanguageContext } from '@ifrc-go/ui/contexts';
1+
import { useMemo } from 'react';
62
import { ErrorBoundary } from '@sentry/react';
73
import {
84
isDefined,
@@ -32,6 +28,8 @@ type overrides = 'mapStyle' | 'mapOptions' | 'navControlShown' | 'navControlPosi
3228
export type Props = Omit<MapProps, overrides> & {
3329
baseLayers?: React.ReactNode;
3430
withDisclaimer?: boolean;
31+
// NOTE: Labels with be added from the country information instead of the
32+
// mapbox layers
3533
withoutLabel?: boolean;
3634
} & Partial<Pick<MapProps, overrides>>;
3735

@@ -79,6 +77,7 @@ function BaseMap(props: Props) {
7977

8078
const countries = useCountry();
8179

80+
// FIXME: We should check for special cases like ICRC, IFRC, etc.
8281
const countryCentroidGeoJson = useMemo(
8382
(): GeoJSON.FeatureCollection<GeoJSON.Geometry> => ({
8483
type: 'FeatureCollection' as const,
@@ -104,34 +103,6 @@ function BaseMap(props: Props) {
104103
[countries],
105104
);
106105

107-
const {
108-
currentLanguage,
109-
} = useContext(LanguageContext);
110-
111-
const adminLabelLayerOptions : Omit<SymbolLayer, 'id'> = useMemo(
112-
() => {
113-
// ar, es, fr
114-
let label: string;
115-
if (currentLanguage === 'es') {
116-
label = 'name_es';
117-
} else if (currentLanguage === 'ar') {
118-
label = 'name_ar';
119-
} else if (currentLanguage === 'fr') {
120-
label = 'name_fr';
121-
} else {
122-
label = 'name';
123-
}
124-
125-
return {
126-
type: 'symbol',
127-
layout: {
128-
'text-field': ['get', label],
129-
},
130-
};
131-
},
132-
[currentLanguage],
133-
);
134-
135106
return (
136107
<Map
137108
mapStyle={mapStyle ?? defaultMapStyle}
@@ -147,18 +118,6 @@ function BaseMap(props: Props) {
147118
sourceKey="composite"
148119
managed={false}
149120
>
150-
<MapLayer
151-
layerKey="admin-0-label"
152-
layerOptions={adminLabelLayerOptions}
153-
/>
154-
<MapLayer
155-
layerKey="admin-0-label-non-independent"
156-
layerOptions={adminLabelLayerOptions}
157-
/>
158-
<MapLayer
159-
layerKey="admin-0-label-priority"
160-
layerOptions={adminLabelLayerOptions}
161-
/>
162121
{baseLayers}
163122
</MapSource>
164123
{!withoutLabel && (
@@ -168,7 +127,7 @@ function BaseMap(props: Props) {
168127
geoJson={countryCentroidGeoJson}
169128
>
170129
<MapLayer
171-
layerKey="point-circle"
130+
layerKey="symbol-label"
172131
layerOptions={adminLabelOverrideOptions}
173132
/>
174133
</MapSource>

0 commit comments

Comments
 (0)