Floorplan Components
Overview
The Warehouse Floor Plan module provides SVG-based zone layout visualization with real-time driver overlay.
Components
FloorplanEditor (Admin Only)
Admin-only floor plan editor with full editing capabilities.
Features:
- SVG upload/import
- Canvas editor with pan & zoom
- Draw rectangular zones (drag to draw)
- Select zone tool (select + move + resize)
- Color picker + label input for zones
- Snap-to-grid toggle
- Undo/Redo basic (stack of changes)
- Save button with debounced autosave
- Zone list panel
- Heatmap toggle
- Driver overlay toggle (real-time markers)
- Export/Import JSON
Location: src/pages/admin/FloorplanEditor.tsx
FloorplanViewer (Read-Only)
Read-only viewer for workers and admins.
Features:
- Load floorplan + zones (read-only)
- Pan & Zoom
- Zone highlighting on hover/click
- Heatmap toggle (read-only)
- Driver overlay toggle
- Hazard Overlay (Phase 3):
- Visual risk heat map with smooth gradients
- Color-coded zones (Green → Yellow → Orange → Red)
- Tooltip details on hover
- Threshold indicators for critical zones
- Manual hazard marking (Safety Officer only)
- Pick & Pack integration:
- Highlight route for current pick list
- Show "Your next zone: Z07" with blinking highlight
- No editing capabilities
Location: src/pages/warehouse/FloorplanViewer.tsx
Backend Functions
lib/floorplan.ts
Core floorplan management functions:
parseSvg()- Extract width, height, viewBox from SVGnormalizeCoordinates()- Normalize coordinates to viewBox unitssanitizeSvg()- Remove scripts/styles (XSS protection)createFloorplan()- Create new floorplanupdateFloorplan()- Update existing floorplancreateZoneFromRect()- Create zone shape from rectangleupdateZoneShape()- Update zone shape propertiesdeleteZoneShape()- Delete zone shapegetFloorplanWithZones()- Get floorplan with all zonescomputeHeatmap()- Compute heatmap data from analyticsmapGeoToSvg()- Map GPS coordinates to SVG (optional)
Security
- SVG content sanitization using
sanitize-html - Tenant isolation via RLS policies
- Admin-only editing (workers read-only)
- Rate limiting on save operations
Integration
- Zones: Links to existing
zonestable - Analytics: Heatmap computed from analytics data
- Driver Locations: Real-time GPS overlay
- Pick & Pack: Route visualization on floor plan
- Hazard Mapping (Phase 3): Predictive safety risk overlay integrated with warehouse floor plan
Hazard Mapping (Phase 3)
Overview
Hazard Mapping provides visual risk overlay on warehouse floor plans, showing predictive safety scores as color-coded zones.
Features
- Automatic Projection: Zone predictive scores are automatically projected to hazard_zones when scores are calculated
- Smooth Gradients: Visual gradients from green (low risk) to red (critical risk)
- Tooltip Details: Hover over zones to see risk score, source (predictive/manual), and notes
- Threshold Indicators: Critical risk zones (70+) show red circle indicators
- Manual Marking: Safety Officers can manually mark hazards with custom risk scores and notes
Color Scheme
- Green (#00ff00): Low risk (0-30)
- Yellow (#ffaa00): Medium risk (30-50)
- Orange (#ff8800): High risk (50-70)
- Red (#ff0000): Critical risk (70-100)
Manual Hazard Marking
Safety Officers can:
- Click on a zone in the floor plan viewer
- Set risk score (0-100) using slider
- Add optional notes
- Save to create/update hazard zone
Database
hazard_zones: Links predictive scores or manual hazards to floor plan zones- Automatically synced when predictive scores are calculated
- Supports both predictive and manual sources
Permissions
- Admin: Full access (create, read, update, delete)
- Worker: Read-only access (viewer)
- Driver: No access
Database Tables
floorplans- Master floor plan recordsfloorplan_zones- Zone shapes on floor plans
See Database Schema for details.