Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW 02 Sutong Jiang #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added assignment/.Rhistory
Empty file.
28 changes: 27 additions & 1 deletion assignment/health_centers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Preloaded healthcenter JSON
var healthCenters = [
const healthCenters = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did not say it explicitly, but you shouldn't edit this file, it's just the data source

{
"LNG":-75.16472099534634,
"LAT":40.034508187448395,
Expand Down Expand Up @@ -541,3 +541,29 @@ var healthCenters = [
"FULL_ADDRESS":"2144 Cecil B Moore Ave"
}
];
]

const keys = [['zip', 'address']]
const targets = healthCenters.filter(item => item.ZIP >= 19140 && item.ZIP <= 19149)
const rows = targets.map(({ ZIP, FULL_ADDRESS }) => ([ZIP, FULL_ADDRESS]))
const result = keys.concat(rows)
console.log('health centers within the zip codes from 19140 to 19149 (inclusive)', result)

const map = L.map('mapid').setView([39.975232206175015, -75.13438358902931], 12)
window.map = map

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map)

const len = targets.length
for (let index = 0; index < len; index += 1) {
const el = targets[index]
const marker = L.marker([el.LAT, el.LNG])
.addTo(map)
.bindPopup(`address: ${el.FULL_ADDRESS}`)

marker.on('click', () => {
marker.openPopup()
})
}