@@ -40,27 +40,37 @@ export default function RestaurantPermitMap() {
4040 const [ currentYearData , setCurrentYearData ] = useState ( [ ] )
4141 const [ year , setYear ] = useState ( 2026 )
4242
43- const yearlyDataEndpoint = `/map-data/?year=${ year } `
43+ const currentUrl = `/map-data/?year=${ year } `
4444
45+ const totalPermits = currentYearData . reduce (
46+ ( acc , curr ) => acc + curr . num_permits ,
47+ 0
48+ )
49+ const maxNumPermits = Math . max ( ...currentYearData . map ( ( c ) => c . num_permits ) )
50+
51+ const communityAreaDict = Object . fromEntries (
52+ currentYearData . map ( ( d ) => [ d . name , d ] )
53+ )
54+
55+ // Get values for community areas
4556 useEffect ( ( ) => {
46- fetch ( )
57+ fetch ( currentUrl )
4758 . then ( ( res ) => res . json ( ) )
48- . then ( ( data ) => {
49- /**
50- * TODO: Fetch the data needed to supply to map with data
51- */
52- } )
53- } , [ yearlyDataEndpoint ] )
59+ . then ( ( data ) => setCurrentYearData ( data ) )
60+ } , [ currentUrl ] )
5461
5562 function setAreaInteraction ( feature , layer ) {
56- /**
57- * TODO: use the methods below to:
58- * 1) shade each area according to how many permits it had in a year
59- * 2) display a popup with area details during user interaction
60- */
61- layer . setStyle ( )
62- layer . on ( "" , ( ) => {
63- layer . bindPopup ( "" )
63+ const thisAreaData = communityAreaDict [ feature . properties . community ] ,
64+ numPermits = thisAreaData . num_permits ,
65+ pcntPermits = numPermits / maxNumPermits
66+ layer . setStyle ( {
67+ fillOpacity : pcntPermits ,
68+ } )
69+ layer . on ( "mouseover" , ( ) => {
70+ layer . bindPopup ( `
71+ <h3>${ feature . properties . community } </h3>
72+ <p>Restaurant permits issued during ${ year } : ${ thisAreaData . num_permits } </p>
73+ ` )
6474 layer . openPopup ( )
6575 } )
6676 }
@@ -69,11 +79,11 @@ export default function RestaurantPermitMap() {
6979 < >
7080 < YearSelect filterVal = { year } setFilterVal = { setYear } />
7181 < p className = "fs-4" >
72- Restaurant permits issued this year: { /* TODO: display this value */ }
82+ Restaurant permits issued this year: { totalPermits || "0" }
7383 </ p >
7484 < p className = "fs-4" >
7585 Maximum number of restaurant permits in a single area:
76- { /* TODO: display this value */ }
86+ { " " + ( maxNumPermits || "0" ) }
7787 </ p >
7888 < MapContainer
7989 id = "restaurant-map"
0 commit comments