-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
29 lines (26 loc) · 1.42 KB
/
map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Load the CSV data using a library such as PapaParse
Papa.parse('./data/data.csv', {
header: true,
download: true,
complete: function(results) {
var dataPoints = results.data; // Store the CSV data as an array of objects
// Define a function to update the heatmap layer with new data based on the selected crime category
function updateHeatmap(crimeCategory) {
var filteredData = dataPoints.filter(function(d) {
return d.crimeCategory === crimeCategory; // Filter the data based on the selected crime category
});
var newDataPoints = filteredData.map(function(d) {
return [d.latitude, d.longitude]; // Extract the lat/long values for the filtered data
});
heatmapLayer.setLatLngs(newDataPoints); // Update the heatmap layer with the new data points
}
// Add a UI element to let the user toggle between different crime categories
var crimeSelect = document.getElementById('crime-select');
crimeSelect.addEventListener('change', function() {
var crimeCategory = this.value; // Get the value of the selected crime category
updateHeatmap(crimeCategory); // Update the heatmap layer with the selected crime category
});
// Initialize the heatmap layer with the first crime category in the dataset
updateHeatmap(dataPoints[0].crimeCategory);
}
});