A web-based application for designing and planning construction zones with AI assistance, ensuring compliance with Winnipeg traffic control regulations.
The Traffic Safety Planner is a tool that allows users to:
- Define road areas on a map
- Create construction zones
- Place traffic control elements (signs, cones, barriers)
- Verify compliance with traffic safety regulations
- Get AI recommendations for proper traffic control setup
The application uses a vector-based approach for placing traffic control elements, taking into account the road direction and construction zone shape to create accurate and compliant layouts.
- Draw a road area as a polygon
- Specify the number of lanes
- Set the road direction using a compass interface
- Visual feedback for the defined road area
- Draw construction zones as polygons
- Automatically analyze road type based on location
- Generate appropriate work zone type recommendations
- Create construction zones based on road type and dimensions
- Vector-based sign placement algorithm
- Automatic detection of the best-aligned edge
- Perpendicular vector calculation for optimal sign placement
- Traffic cone/channelization barrel placement
- Compliance checking against traffic safety regulations
- Toggle different visualization components
- View direction vectors, edges, and sign paths
- Debug inside/outside polygon tests
- Clear all visualizations with one click
- Export traffic plans to JSON files
- Import previously saved plans
- Download map screenshots
The application is organized into several modular JavaScript files, each responsible for a specific part of the functionality:
/traffic-safety-planner/
├── css/
│ └── styles.css # All application styles
├── docs/
│ └── README.md # Project documentation
├── js/
│ ├── main.js # Application entry point and initialization
│ ├── utils.js # Utility functions for calculations
│ ├── modals.js # Dialog and modal components
│ ├── visualization.js # Visualization controls and vector display
│ ├── road-markers.js # Road definition and marker handling
│ ├── traffic-planner.js # AI traffic planner and compliance checking
│ └── search.js # Location search and selection
└── index.html # Main HTML file
- Geographic calculations (distances, bearings, destinations)
- Polygon containment tests
- Helper functions for debouncing, etc.
- Custom confirmation dialogs
- Action selection dialogs
- Road direction selection
- Polygon option dialogs
- Vector visualization with arrows
- Inside/outside polygon tests
- Visibility toggle controls
- Control panel management
- Road area definition
- Interactive marker creation
- Polygon drawing tools
- Construction zone creation
- Traffic control regulations
- Vector-based sign placement algorithm
- Compliance checking
- AI recommendations for fixes
- Location search
- Result suggestions
- Road type analysis
- State export and import
- Map initialization
- Event handlers
- UI coordination
The application uses a vector-based approach for placing traffic control elements:
- Road Direction Vector: Determines the primary direction of traffic flow
- Edge Alignment: Finds the edge of the construction zone that best aligns with the road direction
- Perpendicular Vector Calculation: Calculates vectors perpendicular to the best aligned edge for sign placement
- Sign Placement: Places signs at specific distances along this perpendicular vector
- Road Area Containment: Ensures signs are placed within the defined road area
This approach ensures that traffic control elements are placed logically in relation to the road direction and construction zone.
The application includes built-in knowledge of Winnipeg traffic control regulations:
- TC-2 Roadwork: Short duration work zones
- TC-3 Work Area: Extended duration work zones
- TC-7 Lane Closure: Lane closure configurations
- Residential: 50 km/h speed limit
- Collector: 60 km/h speed limit
- Arterial: 80 km/h speed limit
- Highway: 100 km/h speed limit
- TC-1: Construction Ahead
- TC-2: Roadwork
- TC-3: Work Area
- TC-4: End Construction
- TC-7: Lane Closed
- TC-36: Keep Right
- TC-63: Channelization Barrel
- Open the application in a web browser
- Search for a location or navigate the map
- Define a road area (optional but recommended)
- Create a construction zone
- Use AI planning to place traffic control elements
- Check compliance with regulations
- Export your plan
- Click the "Define Road" button
- Enter the number of lanes
- Click on the map to add points defining the road boundary
- Click "Set Road" when finished
- Use the direction compass to set the road direction
- Click "Save Direction" to confirm
- Click the "Select Area" button
- Click on the map to add points defining the construction zone boundary
- Click "Finish Area" when done
- Choose whether to use AI planning
- Select the road type (residential, collector, arterial, highway)
- Select the work zone type (TC-2, TC-3, TC-7)
- The AI will analyze the construction zone
- Traffic control elements will be placed according to regulations
- Click the "AI Check" button
- The system will analyze your traffic plan
- If compliant, you'll see a success message
- If not compliant, you'll see recommendations for fixes
- Click "Export State" to save your plan as a JSON file
- Click "Import State" to load a previously saved plan
When working with vectors in a geographic context, it's important to remember:
- Latitude increases as you go north
- Longitude increases as you go east
- Map coordinates use a different system than standard vector math
- Road direction is measured in degrees clockwise from north
The road direction vector is calculated as:
const v1 = {
x: Math.sin(bearingRad),
y: -Math.cos(bearingRad) // Negative because y increases southward on maps
};
Edge alignment is determined using the dot product between the road direction vector and each edge vector of the construction zone:
const dotProduct = (v1.x * vector.dx) + (v1.y * vector.dy);
const alignment = Math.abs(dotProduct);
Two perpendicular vectors are calculated and the better one is chosen:
const perpVector1 = {
x: -bestVector.dy, // Perpendicular option 1: (-dy, dx)
y: bestVector.dx
};
const perpVector2 = {
x: bestVector.dy, // Perpendicular option 2: (dy, -dx)
y: -bestVector.dx
};
If signs are not being placed correctly:
- Enable visualization controls
- Check if the road direction vector is correct
- Verify that the perpendicular vector points into the road area
- Check if signs are being placed inside the road area
- Adjust the road area or direction if needed
- Map not loading: Check internet connection and script loading
- Cannot define road: Ensure you have permissions to access your location
- Signs not visible: Check if they're being placed outside the road area
- Export not working: Check browser permissions for file downloads
- 3D visualization of traffic control plans
- More detailed regulatory compliance checks
- Integration with city permitting systems
- Mobile device support
- Collaboration features for team planning
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenStreetMap for mapping data
- Leaflet for the interactive mapping library
- Winnipeg Manual of Temporary Traffic Control for regulations