This document describes how to run the enhanced heatmap feature locally, including fixes for Canvas2D warnings and new disease statistics panels.
python3 ml/generate_sample_dataset.pyThis creates backend/data/heatmap_points.json with ~200 sample points including disease labels.
cd backend
npm install
npm startBackend runs on http://localhost:5000 (or PORT env variable).
Verify backend:
curl http://localhost:5000/api/health
curl http://localhost:5000/api/heatmap | jq '.features | length'In a new terminal:
cd frontend
npm install
npm startFrontend opens at http://localhost:3000 (or 3001 if 3000 is in use).
Problem: Browser console showed warnings:
Canvas2D: Multiple readback operations using getImageData are faster
with the willReadFrequently attribute set to true.
Solution: Created HeatLayerFixed component that:
- Creates a dedicated Leaflet pane for the heatmap layer
- Patches canvas contexts after creation to use
willReadFrequently: true - Uses MutationObserver to detect and patch new canvases as they're added
- Intercepts
getImageDatacalls and routes them through a properly configured context
Files Changed:
frontend/src/components/heatmap/HeatLayerFixed.jsx- New component with canvas patchingfrontend/src/components/HeatMap.jsx- Updated to useHeatLayerFixedinstead of directL.heatLayer
New Features:
-
Disease Information Panel (right side):
- List of 9 major wheat diseases with color-coded icons
- Expandable details showing symptoms, conditions, control measures, and yield loss
- Wheat plant diagram (SVG visualization)
-
Statistical Charts (right panel, below disease info):
- Disease Distribution Bar Chart: Top 5 diseases by count
- Time Series Chart: Disease count over last 14 days
- Economic Impact Chart: Estimated yield loss % per disease (simulated)
Files Created:
frontend/src/components/heatmap/DiseasePanel.jsx- Disease info and statistics panelfrontend/src/components/heatmap/HeatLayerFixed.jsx- Fixed heat layer component
Files Modified:
frontend/src/components/HeatMap.jsx- Integrated new components, added controlsfrontend/package.json- Addedrechartsdependencyml/generate_sample_dataset.py- Added disease label generation
New dependency added:
recharts(^2.10.3) - For statistical charts
Install with:
cd frontend && npm installThe heatmap uses the existing /api/heatmap endpoint. The data format now includes disease_label:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [lng, lat]
},
"properties": {
"intensity": 0.0-1.0,
"disease_prob": 0.0-1.0,
"disease_label": "Brown Rust",
"timestamp": "ISO8601",
"source": "simulated" | "ml"
}
}
]
}To integrate your ML model output:
- Replace
backend/data/heatmap_points.jsonwith your ML model output - Ensure the GeoJSON format matches the structure above
- Include
disease_labelin each feature's properties - The backend will automatically serve the updated data
Alternative: If you prefer a separate endpoint, you can create /api/heatmap/enriched that adds disease labels to existing data. The current implementation works with the main endpoint.
- Open browser DevTools (F12)
- Navigate to Console tab
- Load the heatmap page
- Expected: No Canvas2D warnings about
willReadFrequently - Interact with the map (zoom, pan) - warnings should remain absent
- Heatmap: Should render smoothly without console warnings
- Disease Panel: Right side shows disease list, expandable details, and charts
- Statistics: Charts should display data based on sample dataset
- Controls: Left side toggles and sliders should work
- Point Markers: Toggle should show/hide individual detection points
# Check data includes disease labels
curl http://localhost:5000/api/heatmap | jq '.features[0].properties.disease_label'
# Count features
curl http://localhost:5000/api/heatmap | jq '.features | length'- Heatmap radius and blur are adjustable via sliders (default: radius=18, blur=25)
- Lower values = better performance, higher values = smoother visualization
- Data fetching is debounced (5 seconds) to prevent excessive API calls
- Manual refresh button available in controls panel
- Clear browser cache and reload
- Check browser console for any errors
- Verify
HeatLayerFixedcomponent is being used (check React DevTools)
- Verify
rechartsis installed:npm list recharts - Check browser console for errors
- Ensure data includes
disease_labelandtimestampfields
- Check that "Show Heatmap" toggle is enabled
- Verify data is loading (check Network tab)
- Check browser console for Leaflet/heat errors
Modified:
frontend/src/components/HeatMap.jsx- Main component with new layoutfrontend/package.json- Added recharts dependencyml/generate_sample_dataset.py- Added disease label generation
Created:
frontend/src/components/heatmap/HeatLayerFixed.jsx- Canvas-fixed heat layerfrontend/src/components/heatmap/DiseasePanel.jsx- Disease info and stats panelHEATMAP_README.md- This file
Unchanged:
- Backend API endpoints (except data format enhancement)
- Other frontend components and layouts
- App structure and routing