Skip to content

Commit 4497676

Browse files
Xavier MedranoXavier Medrano
authored andcommitted
remove parts of front end map
1 parent 70cbe85 commit 4497676

1 file changed

Lines changed: 27 additions & 85 deletions

File tree

map/static/js/RestaurantPermitMap.js

Lines changed: 27 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
11
import React, { useEffect, useState, useRef } from "react"
2-
32
import { MapContainer, TileLayer, GeoJSON } from "react-leaflet"
4-
53
import "leaflet/dist/leaflet.css"
64

7-
import RAW_COMMUNITY_AREAS from "../../../data/raw/community-areas.geojson"
85

96
function YearSelect({ setFilterVal }) {
107
// Filter by the permit issue year for each restaurant
11-
const startYear = 2026
12-
const years = [...Array(11).keys()].map((increment) => {
13-
return startYear - increment
14-
})
15-
const options = years.map((year) => {
16-
return (
17-
<option value={year} key={year}>
18-
{year}
19-
</option>
20-
)
21-
})
8+
// TODO: create an element that allows users to select a year between 2016 and 2026
229

23-
return (
24-
<>
25-
<label htmlFor="yearSelect" className="fs-3">
26-
Filter by year:{" "}
27-
</label>
28-
<select
29-
id="yearSelect"
30-
className="form-select form-select-lg mb-3"
31-
onChange={(e) => setFilterVal(e.target.value)}
32-
>
33-
{options}
34-
</select>
35-
</>
36-
)
10+
return
3711
}
3812

3913
export default function RestaurantPermitMap() {
@@ -44,71 +18,41 @@ export default function RestaurantPermitMap() {
4418
const [maxNumPermits, setMaxNumPermits] = useState(null)
4519
const [totalNumPermits, setTotalNumPermits] = useState(null)
4620

47-
// Get values for community areas
21+
/**
22+
* TODO: Use React's useEffect method as many times as needed
23+
* to manage all of the above state variables
24+
*/
4825
useEffect(() => {
49-
fetch(currentUrl)
26+
fetch()
5027
.then((res) => res.json())
51-
.then((data) => {
52-
let tempMaxPermits = 0
53-
54-
// Give each area data on how many restaurant permits were issued within
55-
const areasWithData = RAW_COMMUNITY_AREAS.features.map((area) => {
56-
let numAreaPermits = 0
57-
let result = area
58-
59-
// Loop through permits to assign current area values
60-
for (const permit of data) {
61-
if (permit.community_area_id == area.properties.area_numbe) {
62-
numAreaPermits++
63-
}
64-
}
65-
// Track max number of permits
66-
if (tempMaxPermits < numAreaPermits) {
67-
tempMaxPermits = numAreaPermits
68-
}
69-
70-
result.properties.permits = numAreaPermits
71-
return result
72-
})
73-
74-
// Set state
75-
let temp_comm_areas = Object.assign({}, RAW_COMMUNITY_AREAS)
76-
temp_comm_areas.features = areasWithData
77-
setCommunityAreas(temp_comm_areas)
78-
setMaxNumPermits(tempMaxPermits)
79-
setTotalNumPermits(data.length)
80-
})
81-
}, [setCommunityAreas, currentUrl])
82-
83-
// Set url to be used for filtering
84-
useEffect(() => {
85-
setCurrentUrl(baseUrl.current + `${filterVal}`)
86-
}, [setCurrentUrl, filterVal])
28+
.then((data) => {})
29+
}, [])
8730

8831
function setAreaInteraction(feature, layer) {
89-
const pcntPermits = feature.properties.permits / maxNumPermits
90-
layer.setStyle({
91-
fillOpacity: pcntPermits,
92-
})
93-
layer.on("mouseover", () => {
94-
layer.bindPopup(`
95-
<h3>${feature.properties.community}</h3>
96-
<p>Restaurant permits issued during ${filterVal}: ${feature.properties.permits}</p>
97-
`)
32+
/**
33+
* TODO: use the methods below to:
34+
* 1) shade each area according to how many permits it had in a year
35+
* 2) display a popup with area details during user interaction
36+
*/
37+
layer.setStyle()
38+
layer.on("", () => {
39+
layer.bindPopup("")
9840
layer.openPopup()
9941
})
10042
}
10143

10244
return (
10345
<>
104-
<YearSelect filterVal={filterVal} setFilterVal={setFilterVal} />
46+
<YearSelect />
47+
10548
<p className="fs-4">
106-
Restaurant permits issued this year: {totalNumPermits || "0"}
49+
Restaurant permits issued this year: {/* TODO: display this value */}
10750
</p>
10851
<p className="fs-4">
10952
Maximum number of restaurant permits in a single area:
110-
{" " + (maxNumPermits || "0")}
53+
{/* TODO: display this value */}
11154
</p>
55+
11256
<MapContainer
11357
id="restaurant-map"
11458
center={[41.88, -87.62]}
@@ -119,13 +63,11 @@ export default function RestaurantPermitMap() {
11963
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
12064
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
12165
/>
122-
{communityAreas ? (
123-
<GeoJSON
124-
data={communityAreas}
125-
onEachFeature={setAreaInteraction}
126-
key={maxNumPermits}
127-
/>
128-
) : null}
66+
<GeoJSON
67+
data={communityAreas}
68+
onEachFeature={setAreaInteraction}
69+
key={maxNumPermits}
70+
/>
12971
</MapContainer>
13072
</>
13173
)

0 commit comments

Comments
 (0)