Closed jefroy closed 1 month ago
Extract Relevant Data: Focus on geographic data (state_name
or division_name
for regional granularity), incident_date
for temporal analysis, and counts of incidents and biases (total_offender_count
, offense_name
, bias_desc
) to identify patterns.
Aggregate Data: Depending on the scale of the heatmap, you might want to aggregate data by state or region, summing up the incidents or categorizing them by type of offense and bias.
Set Up Mapbox in Next.js:
npm install mapbox-gl @urbica/react-map-gl
Load and Process CSV Data:
papaparse
to load and parse the CSV data.
npm install papaparse
state_name
to geographic coordinates if using a U.S. map).Create Heatmap Layer:
Add Interactivity:
Style the Map:
Here's a basic outline of what the component might look like in Next.js:
import React, { useEffect, useState } from 'react';
import MapGL from '@urbica/react-map-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
const MapComponent = () => {
const [viewport, setViewport] = useState({
latitude: 37.7749,
longitude: -122.4194,
zoom: 11
});
useEffect(() => {
// Load and process your CSV data here
}, []);
return (
<MapGL
style={{ width: '100%', height: '400px' }}
mapStyle='mapbox://styles/mapbox/streets-v11'
accessToken={process.env.NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN}
latitude={viewport.latitude}
longitude={viewport.longitude}
zoom={viewport.zoom}
onViewportChange={setViewport}
>
{/* Add your heatmap layer here */}
</MapGL>
);
};
export default MapComponent;
This setup uses environment variables for Mapbox credentials (ensure you have a .env.local
file with your NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN
).
Description
We are creating a web application to analyze hate crime trends and patterns across geographical regions. The objective is to provide a heatmap visualization that identifies high-risk areas using data obtained from the FBI. The heatmap will help users understand geographical distribution and patterns in hate crime incidents.
Objectives
Implementation Plan
Data Preparation:
state_name
,incident_date
,offense_name
,bias_desc
).Install Required Libraries:
Map Component Setup:
@urbica/react-map-gl
..env.local
viaNEXT_PUBLIC_MAPBOX_ACCESS_TOKEN
.Load and Process CSV Data:
papaparse
.Create Heatmap Layer:
Interactivity Features:
Map Styling:
Acceptance Criteria
Notes