Skip to content

Commit eb120fe

Browse files
committed
fixed map legend responsiveness issue
1 parent 0fd4a18 commit eb120fe

4 files changed

Lines changed: 158 additions & 185 deletions

File tree

src/components/BMDashboard/InteractiveMap/EmbedInteractiveMap.jsx

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,33 @@ import { useHistory } from 'react-router-dom';
55
import { MapContainer, TileLayer } from 'react-leaflet';
66
import MarkerClusterGroup from '@changey/react-leaflet-markercluster';
77
import axios from 'axios';
8-
import L from 'leaflet';
98
import { ENDPOINTS } from '../../../utils/URL';
10-
import { MapThemeUpdater, Legend, ProjectMarkers, MapUtils } from './MapSharedComponents';
9+
import {
10+
MapThemeUpdater,
11+
ProjectMarkers,
12+
MapUtils,
13+
MapLegend,
14+
ProjectCounter,
15+
} from './MapSharedComponents';
1116

12-
/* -----------------------------------------------------
13-
EMBED INTERACTIVE MAP
14-
----------------------------------------------------- */
1517
function EmbedInteractiveMap() {
1618
const darkMode = useSelector(state => state.theme.darkMode);
1719
const history = useHistory();
1820
const [orgs, setOrgs] = useState([]);
1921
const [loading, setLoading] = useState(true);
2022

21-
// fetch projects/orgs
2223
const fetchOrgs = async () => {
2324
try {
2425
let response;
2526
try {
2627
response = await axios.get(ENDPOINTS.BM_PROJECTS_WITH_LOCATION);
2728
} catch (projectError) {
28-
// Fallback to organization data for now
2929
console.log('Projects with location endpoint not available, using organization data');
3030
response = await axios.get(ENDPOINTS.BM_ORGS_WITH_LOCATION);
3131
}
3232

3333
const data = response.data.data || [];
3434

35-
// If no data from backend, use pseudo data
3635
if (data.length === 0) {
3736
console.log('No data from backend, using pseudo data');
3837
const pseudoData = MapUtils.getPseudoOrgs();
@@ -43,7 +42,6 @@ function EmbedInteractiveMap() {
4342
return data;
4443
} catch (error) {
4544
console.error('Error fetching project/org data:', error);
46-
// If fetch fails, use pseudo data
4745
const pseudoData = MapUtils.getPseudoOrgs();
4846
setOrgs(pseudoData);
4947
return [];
@@ -53,7 +51,6 @@ function EmbedInteractiveMap() {
5351
};
5452

5553
const handleProjectClick = org => {
56-
// Navigate to project details page
5754
history.push(`/bmdashboard/projects/${org.orgId}`);
5855
};
5956

@@ -71,25 +68,13 @@ function EmbedInteractiveMap() {
7168
background: darkMode ? '#0d1b2a' : 'white',
7269
}}
7370
>
74-
{/* Project counter for embed version */}
75-
<div
76-
style={{
77-
position: 'absolute',
78-
left: '15px',
79-
top: '15px',
80-
padding: '8px 12px',
81-
background: darkMode ? 'rgba(30, 42, 58, 0.9)' : 'rgba(255, 255, 255, 0.9)',
82-
borderRadius: '6px',
83-
fontSize: '13px',
84-
backdropFilter: 'blur(10px)',
85-
color: darkMode ? 'white' : '#222',
86-
border: darkMode ? '1px solid #3a506b' : '1px solid rgba(0,0,0,0.1)',
87-
zIndex: 1000,
88-
fontWeight: '500',
89-
}}
90-
>
91-
Showing {orgs.length} projects
92-
</div>
71+
<ProjectCounter
72+
count={orgs.length}
73+
darkMode={darkMode}
74+
position="bottomleft"
75+
isEmbed={true}
76+
/>
77+
<MapLegend position="bottomleft" darkMode={darkMode} isEmbed={true} />
9378

9479
<MapContainer
9580
center={[20, 0]}
@@ -109,7 +94,6 @@ function EmbedInteractiveMap() {
10994
worldCopyJump
11095
>
11196
<MapThemeUpdater darkMode={darkMode} />
112-
11397
<TileLayer
11498
noWrap={false}
11599
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
@@ -121,9 +105,6 @@ function EmbedInteractiveMap() {
121105
minZoom={1}
122106
maxZoom={15}
123107
/>
124-
125-
<Legend position="bottomleft" />
126-
127108
<MarkerClusterGroup
128109
disableClusteringAtZoom={13}
129110
spiderfyOnMaxZoom={true}

src/components/BMDashboard/InteractiveMap/InteractiveMap.jsx

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { MapContainer, TileLayer } from 'react-leaflet';
66
import MarkerClusterGroup from '@changey/react-leaflet-markercluster';
77
import axios from 'axios';
88
import { ENDPOINTS } from '../../../utils/URL';
9-
import { MapThemeUpdater, Legend, ProjectMarkers, MapUtils } from './MapSharedComponents';
9+
import {
10+
MapThemeUpdater,
11+
ProjectMarkers,
12+
MapUtils,
13+
MapLegend,
14+
ProjectCounter,
15+
} from './MapSharedComponents';
1016
import 'leaflet/dist/leaflet.css';
1117
import styles from './InteractiveMap.module.css';
1218

@@ -22,9 +28,6 @@ export default function InteractiveMap() {
2228
const [mapKey, setMapKey] = useState(0);
2329
const [errMsg, setErrMsg] = useState('');
2430

25-
/* -----------------------------------------
26-
FETCH
27-
----------------------------------------- */
2831
const fetchOrgs = async () => {
2932
try {
3033
let response;
@@ -35,11 +38,8 @@ export default function InteractiveMap() {
3538
}
3639

3740
const data = response.data.data || [];
38-
39-
// Print fetched data to check if backend is correct
4041
console.log('Backend data fetched:', data);
4142

42-
// If no data from backend, use pseudo data
4343
if (data.length === 0) {
4444
console.log('No data from backend, using pseudo data');
4545
const pseudoData = MapUtils.getPseudoOrgs();
@@ -51,7 +51,6 @@ export default function InteractiveMap() {
5151
}
5252
} catch (e) {
5353
console.error('Error fetching data:', e);
54-
// If fetch fails, use pseudo data
5554
const pseudoData = MapUtils.getPseudoOrgs();
5655
setOrgs(pseudoData);
5756
setFilteredOrgs(pseudoData);
@@ -60,9 +59,6 @@ export default function InteractiveMap() {
6059
}
6160
};
6261

63-
/* -----------------------------------------
64-
FILTERING
65-
----------------------------------------- */
6662
const applyDateFilters = () => {
6763
if (startDate && endDate && new Date(endDate) < new Date(startDate)) {
6864
setErrMsg('End date cannot be earlier than start date');
@@ -86,9 +82,6 @@ export default function InteractiveMap() {
8682

8783
const handleProjectClick = org => history.push(`/bmdashboard/projects/${org.orgId}`);
8884

89-
/* -----------------------------------------
90-
EFFECTS
91-
----------------------------------------- */
9285
useEffect(() => {
9386
fetchOrgs();
9487
}, []);
@@ -97,17 +90,10 @@ export default function InteractiveMap() {
9790
setMapKey(k => k + 1);
9891
}, [darkMode]);
9992

100-
/* -----------------------------------------
101-
STYLES
102-
----------------------------------------- */
10393
const S = MapUtils.getMapStyles(darkMode);
10494

105-
/* -----------------------------------------
106-
RENDER
107-
----------------------------------------- */
10895
return (
10996
<div style={S.container}>
110-
{/* HEADER ROW — Title (left) + Filters (right) */}
11197
<div style={S.headerRow}>
11298
<h2 style={S.titleText}>Global Distribution and Project Status Overview</h2>
11399

@@ -137,12 +123,14 @@ export default function InteractiveMap() {
137123
</div>
138124
</div>
139125

140-
{/* MAP — full width, flexible height */}
141126
<div style={S.mapArea}>
142-
{/* Bottom-left label inside map */}
143-
<div style={S.bottomLeftLabel}>
144-
Showing {filteredOrgs.length} of {orgs.length} projects
145-
</div>
127+
<ProjectCounter
128+
count={filteredOrgs.length}
129+
total={orgs.length}
130+
darkMode={darkMode}
131+
position="bottomleft"
132+
/>
133+
<MapLegend position="bottomright" darkMode={darkMode} />
146134

147135
{loading ? (
148136
<div
@@ -161,10 +149,12 @@ export default function InteractiveMap() {
161149
center={[40, 0]}
162150
zoom={3}
163151
scrollWheelZoom
164-
style={{ width: '100%', height: '100%' }}
152+
style={{
153+
width: '100%',
154+
height: '100%',
155+
}}
165156
>
166157
<MapThemeUpdater darkMode={darkMode} />
167-
168158
<TileLayer
169159
url={
170160
darkMode
@@ -173,9 +163,6 @@ export default function InteractiveMap() {
173163
}
174164
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
175165
/>
176-
177-
<Legend />
178-
179166
<MarkerClusterGroup maxClusterRadius={70} chunkedLoading spiderfyOnMaxZoom={true}>
180167
<ProjectMarkers
181168
orgs={filteredOrgs}

src/components/BMDashboard/InteractiveMap/InteractiveMap.module.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
/* Light Mode Map */
23
:global(.light-mode-map) {
34
background-color: white;
@@ -9,6 +10,15 @@
910
background-color: #0d1b2a;
1011
}
1112

13+
/* Remove underline from zoom controls */
14+
:global(.leaflet-control-zoom a) {
15+
text-decoration: none !important;
16+
}
17+
18+
:global(.leaflet-control-zoom a:hover) {
19+
text-decoration: none !important;
20+
}
21+
1222
/* Remove default popup background and styling */
1323
:global(.leaflet-popup-content-wrapper) {
1424
background: transparent !important;
@@ -137,22 +147,26 @@
137147
color: white !important;
138148
border-color: #3a506b !important;
139149
transition: all 0.2s ease;
150+
text-decoration: none !important;
140151
}
141152

142153
:global(.dark-mode-map .leaflet-control-zoom a:hover) {
143154
background-color: #3a506b !important;
144155
transform: translateY(-1px);
156+
text-decoration: none !important;
145157
}
146158

147159
:global(.light-mode-map .leaflet-control-zoom a) {
148160
background-color: white !important;
149161
color: #222 !important;
150162
border-color: #ddd !important;
151163
transition: all 0.2s ease;
164+
text-decoration: none !important;
152165
}
153166

154167
:global(.light-mode-map .leaflet-control-zoom a:hover) {
155168
background-color: #f5f5f5 !important;
169+
text-decoration: none !important;
156170
}
157171

158172
:global(.dark-mode-map .leaflet-control-zoom-in),

0 commit comments

Comments
 (0)