Traffic Reporting
The Traffic Reporting feature enables users to submit traffic incidents and view recent reports from the community, helping everyone stay informed about current road conditions.
Overview
This collaborative feature allows users to:
Report traffic incidents in real-time
View recent incidents from other users
Provide detailed information about road hazards
Help the community make informed routing decisions
How to Use
Enter Location
Specify the street or intersection where the incident occurred.
Specify Incident Type
Describe the type of incident (e.g., accident, blockage, construction, hazard).
Add Details (Optional)
Provide additional information about the incident in the details field.
Submit Report
Click the “Submit Incident” button to share the report with the community.
View Recent Incidents
Scroll down to see a list of recent incidents reported by other users.
API Integration
The reporting system uses the following API endpoint:
const API_URL = 'https://autonomous.stu.nighthawkcodingsociety.com/api/incidents' ;
Submit Incident (POST)
document . getElementById ( 'incidentForm' ). addEventListener ( 'submit' , async ( e ) => {
e . preventDefault ();
const location = document . getElementById ( 'location' ). value ;
const type = document . getElementById ( 'type' ). value ;
const details = document . getElementById ( 'details' ). value ;
const res = await fetch ( 'https://autonomous.stu.nighthawkcodingsociety.com/api/incidents' , {
method: 'POST' ,
headers: { 'Content-Type' : 'application/json' },
body: JSON . stringify ({ location , type , details })
});
const data = await res . json ();
document . getElementById ( 'statusMessage' ). innerText = data . message || 'Incident reported.' ;
document . getElementById ( 'incidentForm' ). reset ();
loadIncidents (); // refresh list
});
Request Parameters
Parameter Type Required Description locationstring Yes Street or intersection of the incident typestring Yes Type of incident (accident, blockage, etc.) detailsstring No Additional information about the incident
Load Incidents (GET)
async function loadIncidents () {
const res = await fetch ( 'https://autonomous.stu.nighthawkcodingsociety.com/api/incidents' );
const data = await res . json ();
const list = document . getElementById ( 'incidentList' );
list . innerHTML = '' ;
data . forEach (( incident ) => {
list . innerHTML += `<li><strong> ${ incident . type } </strong> at <em> ${ incident . location } </em><br> ${ incident . details || '' } </li>` ;
});
}
loadIncidents ();
The incident list is automatically loaded when the page first loads and refreshes after each new submission.
UI Components
Report Form Clean submission form with required and optional fields
Status Messages Real-time feedback on submission success
Incident List Organized display of recent community reports
Auto-refresh List updates automatically after new submissions
< div class = "report-container" >
< h2 class = "title" > 🚦 Report Traffic Incident </ h2 >
< form id = "incidentForm" >
< input type = "text" id = "location" placeholder = "Enter Street or Intersection" required >
< input type = "text" id = "type" placeholder = "Type of Incident (e.g., accident, blockage)" required >
< textarea id = "details" placeholder = "Optional details..." rows = "3" ></ textarea >
< button type = "submit" > Submit Incident </ button >
</ form >
< div id = "statusMessage" ></ div >
</ div >
Incident Display
Recent Incidents Section
< div class = "incidents-display" >
< h3 > 📍 Recent Incidents </ h3 >
< ul id = "incidentList" ></ ul >
</ div >
Dynamic List Generation
Incidents are rendered with type, location, and details:
data . forEach (( incident ) => {
list . innerHTML += `<li><strong> ${ incident . type } </strong> at <em> ${ incident . location } </em><br> ${ incident . details || '' } </li>` ;
});
Optional details are only displayed if provided, keeping the list clean when additional information isn’t available.
Styling
The interface features a modern, accessible design:
.report-container , .incidents-display {
max-width : 600 px ;
margin : 20 px auto ;
background : #f9f9f9 ;
padding : 20 px ;
border-radius : 12 px ;
box-shadow : 0 2 px 12 px rgba ( 0 , 0 , 0 , 0.1 );
font-family : Arial , sans-serif ;
}
input , textarea {
width : 100 % ;
margin : 8 px 0 ;
padding : 10 px ;
border : 1 px solid #ccc ;
border-radius : 6 px ;
}
button {
background-color : #007bff ;
color : white ;
border : none ;
padding : 12 px ;
border-radius : 6 px ;
cursor : pointer ;
}
button :hover {
background-color : #0056b3 ;
}
Incident List Styling
ul {
list-style-type : none ;
padding-left : 0 ;
}
li {
margin : 8 px 0 ;
background : #eee ;
padding : 10 px ;
border-radius : 8 px ;
}
The form uses HTML5 validation:
Both location and type fields are marked as required: < input type = "text" id = "location" placeholder = "Enter Street or Intersection" required >
< input type = "text" id = "type" placeholder = "Type of Incident (e.g., accident, blockage)" required >
The details field allows users to provide additional context without being mandatory: < textarea id = "details" placeholder = "Optional details..." rows = "3" ></ textarea >
Response Handling
Submission Feedback
const data = await res . json ();
document . getElementById ( 'statusMessage' ). innerText = data . message || 'Incident reported.' ;
document . getElementById ( 'incidentForm' ). reset ();
loadIncidents ();
After successful submission:
A status message is displayed
The form is automatically reset
The incident list refreshes to show the new report
Common Incident Types
While the type field accepts any text, common incident types include:
Accident Vehicle collisions or crashes
Blockage Road closures or lane blockages
Construction Active construction zones
Hazard Road hazards like debris or potholes
Congestion Heavy traffic or congestion
Weather Weather-related conditions
Data Structure
Incident objects contain:
Field Type Description locationstring Street or intersection typestring Incident category detailsstring Optional additional information
Best Practices
When reporting incidents:
Be specific about the location
Use clear, descriptive incident types
Include relevant details that help other drivers
Only report current, active incidents
Automatic Page Load
Incidents are loaded immediately when the page is accessed:
This ensures users always see the most recent community reports upon arrival.
The Traffic Reporting feature creates a collaborative environment where:
Users help each other avoid delays
Real-time information improves route planning
The community stays informed about road conditions
Shared knowledge enhances overall navigation efficiency