-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add emergency project map in country page ongoint threeW activities tab
- Loading branch information
1 parent
c575282
commit 44be892
Showing
6 changed files
with
362 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/views/CountryOngoingActivitiesThreeWActivities/ResponseActivitiesMap/i18n.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"namespace": "emergencyActivities", | ||
"strings": { | ||
"severityLow": "Less than 2", | ||
"severityMedium": "2 to 4", | ||
"severityHigh": "5 to 9", | ||
"severitySevere": "10 or more", | ||
"numberOfProjects": "Number of Projects" | ||
} | ||
} |
195 changes: 195 additions & 0 deletions
195
src/views/CountryOngoingActivitiesThreeWActivities/ResponseActivitiesMap/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import { useMemo } from 'react'; | ||
import { | ||
_cs, | ||
isDefined, | ||
isNotDefined, | ||
mapToList, | ||
} from '@togglecorp/fujs'; | ||
import { | ||
useOutletContext, | ||
} from 'react-router-dom'; | ||
import type { FillLayer } from 'mapbox-gl'; | ||
import { | ||
MapLayer, | ||
MapBounds, | ||
} from '@togglecorp/re-map'; | ||
import getBbox from '@turf/bbox'; | ||
|
||
import LegendItem from '#components/LegendItem'; | ||
import MapContainerWithDisclaimer from '#components/MapContainerWithDisclaimer'; | ||
import useTranslation from '#hooks/useTranslation'; | ||
import type { CountryOutletContext } from '#utils/outletContext'; | ||
import { | ||
DURATION_MAP_ZOOM, | ||
DEFAULT_MAP_PADDING, | ||
COLOR_LIGHT_GREY, | ||
} from '#utils/constants'; | ||
import BaseMap from '#components/domain/BaseMap'; | ||
|
||
import i18n from './i18n.json'; | ||
import styles from './styles.module.css'; | ||
|
||
const COLOR_SEVERITY_LOW = '#ccd2d9'; | ||
const COLOR_SEVERITY_MEDIUM = '#99a5b4'; | ||
const COLOR_SEVERITY_HIGH = '#67788d'; | ||
const COLOR_SEVERITY_SEVERE = '#344b67'; | ||
|
||
const SEVERITY_LOW = 2; | ||
const SEVERITY_MEDIUM = 5; | ||
const SEVERITY_HIGH = 10; | ||
|
||
interface Props { | ||
className?: string; | ||
sidebarContent?: React.ReactNode; | ||
emergencyProjectCountByDistrict: Record<number, number>; | ||
} | ||
|
||
function ResponseActivitiesMap(props: Props) { | ||
const { | ||
className, | ||
sidebarContent, | ||
emergencyProjectCountByDistrict, | ||
} = props; | ||
|
||
const strings = useTranslation(i18n); | ||
const { | ||
// countryId, | ||
countryResponse, | ||
} = useOutletContext<CountryOutletContext>(); | ||
|
||
const bounds = useMemo( | ||
() => (countryResponse ? getBbox(countryResponse?.bbox) : undefined), | ||
[countryResponse], | ||
); | ||
|
||
const emergencyProjectCountByDistrictList = mapToList( | ||
emergencyProjectCountByDistrict, | ||
(value, key) => ({ district: key, count: value }), | ||
); | ||
|
||
const districtIdList = useMemo( | ||
() => emergencyProjectCountByDistrictList.map( | ||
(list) => Number(list.district), | ||
), | ||
[emergencyProjectCountByDistrictList], | ||
); | ||
|
||
const adminOneLabelSelectedLayerOptions = useMemo<Omit<FillLayer, 'id'>>( | ||
() => ({ | ||
type: 'fill', | ||
layout: { visibility: 'visible' }, | ||
filter: [ | ||
'in', | ||
'district_id', | ||
...districtIdList, | ||
], | ||
}), | ||
[districtIdList], | ||
); | ||
|
||
const adminOneHighlightLayerOptions = useMemo<Omit<FillLayer, 'id'>>( | ||
() => { | ||
if (isNotDefined((emergencyProjectCountByDistrictList)) | ||
|| emergencyProjectCountByDistrictList.length < 1) { | ||
return { | ||
type: 'fill', | ||
layout: { visibility: 'visible' }, | ||
paint: { | ||
'fill-color': COLOR_LIGHT_GREY, | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
type: 'fill', | ||
layout: { visibility: 'visible' }, | ||
paint: { | ||
'fill-color': [ | ||
'match', | ||
['get', 'district_id'], | ||
...(emergencyProjectCountByDistrictList).flatMap(({ district, count }) => [ | ||
Number(district), | ||
[ | ||
'interpolate', | ||
['exponential', 1], | ||
['number', count], | ||
0, | ||
COLOR_SEVERITY_LOW, | ||
SEVERITY_LOW, | ||
COLOR_SEVERITY_MEDIUM, | ||
SEVERITY_MEDIUM, | ||
COLOR_SEVERITY_HIGH, | ||
SEVERITY_HIGH, | ||
COLOR_SEVERITY_SEVERE, | ||
], | ||
]), | ||
COLOR_LIGHT_GREY, | ||
], | ||
}, | ||
}; | ||
}, | ||
[emergencyProjectCountByDistrictList], | ||
); | ||
|
||
return ( | ||
<div className={_cs(styles.map, className)}> | ||
<div className={styles.mapWithLegend}> | ||
<BaseMap | ||
baseLayers={( | ||
<> | ||
<MapLayer | ||
layerKey="admin-1-highlight" | ||
layerOptions={adminOneHighlightLayerOptions} | ||
/> | ||
<MapLayer | ||
layerKey="admin-1-label-selected" | ||
layerOptions={adminOneLabelSelectedLayerOptions} | ||
/> | ||
</> | ||
)} | ||
> | ||
<MapContainerWithDisclaimer | ||
className={styles.mapContainer} | ||
footer={( | ||
<div className={styles.legend}> | ||
<div className={styles.label}> | ||
{strings.numberOfProjects} | ||
</div> | ||
<LegendItem | ||
color={COLOR_SEVERITY_LOW} | ||
label={strings.severityLow} | ||
/> | ||
<LegendItem | ||
color={COLOR_SEVERITY_MEDIUM} | ||
label={strings.severityMedium} | ||
/> | ||
<LegendItem | ||
color={COLOR_SEVERITY_HIGH} | ||
label={strings.severityHigh} | ||
/> | ||
<LegendItem | ||
color={COLOR_SEVERITY_SEVERE} | ||
label={strings.severitySevere} | ||
/> | ||
</div> | ||
)} | ||
/> | ||
{isDefined(bounds) && ( | ||
<MapBounds | ||
duration={DURATION_MAP_ZOOM} | ||
bounds={bounds} | ||
padding={DEFAULT_MAP_PADDING} | ||
/> | ||
)} | ||
</BaseMap> | ||
</div> | ||
{sidebarContent && ( | ||
<div className={styles.sidebar}> | ||
{sidebarContent} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default ResponseActivitiesMap; |
53 changes: 53 additions & 0 deletions
53
src/views/CountryOngoingActivitiesThreeWActivities/ResponseActivitiesMap/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.map { | ||
display: flex; | ||
gap: var(--go-ui-spacing-md); | ||
height: 40rem; | ||
overflow: auto; | ||
|
||
.map-with-legend { | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
|
||
.map-container { | ||
flex-grow: 1; | ||
} | ||
|
||
.legend { | ||
display: flex; | ||
flex-wrap: wrap; | ||
background-color: var(--go-ui-color-background); | ||
gap: var(--go-ui-spacing-sm) var(--go-ui-spacing-md); | ||
padding: var(--go-ui-spacing-md); | ||
|
||
.label { | ||
font-weight: var(--go-ui-font-weight-medium); | ||
} | ||
} | ||
} | ||
|
||
.sidebar { | ||
flex-basis: calc(14vw + 12rem); | ||
background-color: var(--go-ui-color-background); | ||
overflow: auto; | ||
} | ||
|
||
@media screen and (max-width: 50rem) { | ||
flex-direction: column; | ||
height: initial; | ||
|
||
.sidebar { | ||
flex-basis: unset; | ||
} | ||
|
||
.map-with-legend { | ||
height: min(40rem, 60vh); | ||
} | ||
} | ||
} | ||
|
||
.map-popup-content { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--go-ui-spacing-md); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.