-
Notifications
You must be signed in to change notification settings - Fork 30
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
HW4-Zixuan Xu #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,14 @@ | |
Remember, this is open-ended. Open ended doesn't mean pointless: we're looking for | ||
filters that might actually be useful. Try to see what you can produce. | ||
===================== */ | ||
|
||
var phillyCrimeDataUrl = "https://raw.githubusercontent.com/CPLN692-MUSA611/datasets/master/json/philadelphia-crime-snippet.json"; | ||
/* ===================== | ||
Define a resetMap function to remove markers from the map and clear the array of markers | ||
===================== */ | ||
var resetMap = function() { | ||
var resetMap = function(myMarkers) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
_.forEach(myMarkers, function(m) { | ||
map.removeLayer(m); | ||
}); | ||
/* ===================== | ||
Fill out this function definition | ||
===================== */ | ||
|
@@ -39,6 +42,9 @@ var resetMap = function() { | |
it down! | ||
===================== */ | ||
var getAndParseData = function() { | ||
$.ajax(phillyCrimeDataUrl).done(function(res) { | ||
myData = JSON.parse(res); | ||
}); | ||
/* ===================== | ||
Fill out this function definition | ||
===================== */ | ||
|
@@ -49,6 +55,18 @@ var getAndParseData = function() { | |
criteria happens to be — that's entirely up to you) | ||
===================== */ | ||
var plotData = function() { | ||
_.forEach(myData, function(x){ | ||
var marker; | ||
if (booleanField && x["UCR Code"] == 600) { | ||
marker = L.marker([x.Lat, x.Lng]).bindPopup(x["General Crime Category"]).addTo(map); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't requested clarifying comments before this HW was due... but for next time, it'd be helpful to have some comments to help understand what it is you are trying to filter here by so I could get a good idea from the outset without needing to understand all the logic. But it looks good. |
||
if (numericField1 !== "" && numericField2 !== "" && x.PSA > numericField1 && x.PSA < numericField2) { | ||
marker = L.marker([x.Lat, x.Lng]).bindPopup("PSA - " + x.PSA + ": " + x["General Crime Category"]).addTo(map); | ||
}} | ||
if (stringField !== "" && x["General Crime Category"] == stringField) { | ||
marker = L.marker([x.Lat, x.Lng]).bindPopup(x["General Crime Category"]).addTo(map); | ||
} | ||
myMarkers.push(marker); | ||
}); | ||
/* ===================== | ||
Fill out this function definition | ||
===================== */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small improvement suggestion: using
_.map
instead of_.each
, which creates the array and doesn't require thepush