@@ -33,7 +33,7 @@ const mapStyles = [
33
33
{ url : 'mapbox://styles/mapbox/satellite-v9' , name : 'Satellite' , image : SatelliteMode } ,
34
34
] ;
35
35
36
- const AirQoMap = ( { customStyle, mapboxApiAccessToken, showSideBar, pollutant } ) => {
36
+ const AirQoMap = ( { customStyle, mapboxApiAccessToken, showSideBar, pollutant, resizeMap } ) => {
37
37
const dispatch = useDispatch ( ) ;
38
38
const mapContainerRef = useRef ( null ) ;
39
39
const mapRef = useRef ( null ) ;
@@ -48,6 +48,7 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
48
48
const [ toastMessage , setToastMessage ] = useState ( {
49
49
message : '' ,
50
50
type : '' ,
51
+ bgColor : '' ,
51
52
} ) ;
52
53
const [ NodeType , setNodeType ] = useState ( 'Emoji' ) ;
53
54
const [ selectedSite , setSelectedSite ] = useState ( null ) ;
@@ -60,10 +61,13 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
60
61
/**
61
62
* Clear data on unmount
62
63
* @sideEffect
63
- * - Clear data
64
+ * - Clear data on unmount when lat, lng and zm are not present
65
+ * @returns {void }
64
66
*/
65
67
useEffect ( ( ) => {
66
- dispatch ( clearData ( ) ) ;
68
+ if ( ! lat && ! lng && ! zm ) {
69
+ dispatch ( clearData ( ) ) ;
70
+ }
67
71
} , [ ] ) ;
68
72
69
73
/**
@@ -129,6 +133,13 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
129
133
130
134
/**
131
135
* Initialize the map
136
+ * @sideEffect
137
+ * - Initialize the map
138
+ * - Add map controls
139
+ * - Load data
140
+ * - Update clusters
141
+ * - Fetch location boundaries
142
+ * @returns {void }
132
143
*/
133
144
useEffect ( ( ) => {
134
145
const initializeMap = async ( ) => {
@@ -263,6 +274,12 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
263
274
const marker = new mapboxgl . Marker ( el )
264
275
. setLngLat ( feature . geometry . coordinates )
265
276
. addTo ( map ) ;
277
+
278
+ // Add click event to zoom in when a user clicks on a cluster
279
+ el . addEventListener ( 'click' , ( ) => {
280
+ map . flyTo ( { center : feature . geometry . coordinates , zoom : zoom + 2 } ) ;
281
+ } ) ;
282
+
266
283
markers . push ( marker ) ;
267
284
}
268
285
} ) ;
@@ -287,6 +304,17 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
287
304
} ;
288
305
} , [ mapStyle , mapboxApiAccessToken , refresh , pollutant , NodeType ] ) ;
289
306
307
+ /**
308
+ * Resize the map
309
+ * @sideEffect
310
+ * - Resizes the map when the window is resized and side bar is closed
311
+ */
312
+ useEffect ( ( ) => {
313
+ if ( ! resizeMap ) {
314
+ mapRef . current . resize ( ) ;
315
+ }
316
+ } , [ ! resizeMap ] ) ;
317
+
290
318
/**
291
319
* Fetch location boundaries
292
320
*/
@@ -399,6 +427,7 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
399
427
setToastMessage ( {
400
428
message : 'Location URL copied to clipboard' ,
401
429
type : 'success' ,
430
+ bgColor : 'bg-blue-600' ,
402
431
} ) ;
403
432
} catch ( error ) {
404
433
setToastMessage ( {
@@ -409,17 +438,14 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
409
438
} ;
410
439
411
440
return (
412
- < div className = 'relative w-auto h-auto ' >
441
+ < div className = 'relative w-full h-full ' >
413
442
{ /* Map */ }
414
443
< div ref = { mapContainerRef } className = { customStyle } />
415
444
416
445
{ /* Loader */ }
417
446
{ refresh ||
418
447
( loading && (
419
- < div
420
- className = { `absolute inset-0 flex items-center justify-center z-40 ${
421
- showSideBar ? 'ml-96' : ''
422
- } `} >
448
+ < div className = { `absolute inset-0 flex items-center justify-center z-40` } >
423
449
< div className = 'bg-white w-[70px] h-[70px] flex justify-center items-center rounded-md shadow-md' >
424
450
< span className = 'ml-2' >
425
451
< Loader width = { 32 } height = { 32 } />
@@ -478,7 +504,7 @@ const AirQoMap = ({ customStyle, mapboxApiAccessToken, showSideBar, pollutant })
478
504
timeout = { 3000 }
479
505
dataTestId = 'map-toast'
480
506
size = 'lg'
481
- bgColor = 'bg-blue-600'
507
+ bgColor = { toastMessage . bgColor }
482
508
position = 'bottom'
483
509
/>
484
510
) }
0 commit comments