Skip to content

Commit 87e75a6

Browse files
frozenheliumtnagorra
authored andcommitted
Create a GlobalMap component
- Use GlobalMap in the ActiveOperationMap
1 parent efd1d1a commit 87e75a6

File tree

6 files changed

+270
-69
lines changed

6 files changed

+270
-69
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, { 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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import {
2-
useContext,
3-
useMemo,
4-
} from 'react';
5-
import { LanguageContext } from '@ifrc-go/ui/contexts';
1+
import { useMemo } from 'react';
2+
// import { LanguageContext } from '@ifrc-go/ui/contexts';
63
import { ErrorBoundary } from '@sentry/react';
74
import {
85
isDefined,
@@ -104,10 +101,9 @@ function BaseMap(props: Props) {
104101
[countries],
105102
);
106103

107-
const {
108-
currentLanguage,
109-
} = useContext(LanguageContext);
104+
// const { currentLanguage } = useContext(LanguageContext);
110105

106+
/*
111107
const adminLabelLayerOptions : Omit<SymbolLayer, 'id'> = useMemo(
112108
() => {
113109
// ar, es, fr
@@ -131,6 +127,7 @@ function BaseMap(props: Props) {
131127
},
132128
[currentLanguage],
133129
);
130+
*/
134131

135132
return (
136133
<Map
@@ -147,18 +144,6 @@ function BaseMap(props: Props) {
147144
sourceKey="composite"
148145
managed={false}
149146
>
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-
/>
162147
{baseLayers}
163148
</MapSource>
164149
{!withoutLabel && (

0 commit comments

Comments
 (0)