A full-stack application for visualizing wheat disease detection data using Leaflet heatmaps. Integrates React frontend, Node.js backend, and Python ML data generation.
heatmap/
├── backend/ # Node.js/Express API server
│ ├── data/ # Heatmap data (generated by Python script)
│ ├── routes/ # API routes
│ └── test/ # Unit tests
├── frontend/ # React application
│ └── src/
│ └── components/
└── ml/ # Python ML data generation
└── generate_sample_dataset.py
First, generate the sample dataset:
python ml/generate_sample_dataset.pyThis creates backend/data/heatmap_points.json with ~200 sample detection points across India.
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 in your browser.
- Map of India with OpenStreetMap tiles
- Heatmap overlay showing disease intensity (red = high, blue = low)
- Controls panel (top-right) to toggle heatmap and point markers
- Legend showing color intensity scale
- Point markers (when enabled) showing individual detections with disease probability tooltips
Health check endpoint.
Example:
curl http://localhost:5000/api/healthResponse:
{
"status": "ok",
"timestamp": "2024-01-01T00:00:00.000Z"
}Returns GeoJSON FeatureCollection with wheat disease detection data.
Example:
curl http://localhost:5000/api/heatmap | jq '.features[0]'Response:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [lng, lat]
},
"properties": {
"intensity": 0.0-1.0,
"disease_prob": 0.0-1.0,
"timestamp": "ISO8601",
"source": "simulated" | "ml"
}
}
]
}The backend expects backend/data/heatmap_points.json to be a GeoJSON FeatureCollection:
- type:
"FeatureCollection" - features: Array of Feature objects
- geometry: Point with
[lng, lat]coordinates - properties:
intensity: 0.0-1.0 (used for heatmap visualization)disease_prob: 0.0-1.0 (ML model probability)timestamp: ISO8601 timestampsource:"simulated"or"ml"
- geometry: Point with
For ML team integration:
- Replace
ml/generate_sample_dataset.pywith your actual ML inference pipeline - Output data in the same GeoJSON FeatureCollection format
- Save to
backend/data/heatmap_points.json - The backend will automatically serve the updated data
Example ML output format:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [lng, lat]},
"properties": {
"intensity": 0.85,
"disease_prob": 0.87,
"timestamp": "2024-01-01T12:00:00Z",
"source": "ml"
}
}
]
}cd backend
npm test# Health check
curl http://localhost:5000/api/health
# Get heatmap data
curl http://localhost:5000/api/heatmap | jq '.features | length'
# Check first feature
curl http://localhost:5000/api/heatmap | jq '.features[0]'PORT: Server port (default: 5000)
REACT_APP_API_URL: Backend API URL (default:http://localhost:5000)
- Frontend: React, react-leaflet, Leaflet, leaflet.heat
- Backend: Node.js, Express, CORS
- Data Generation: Python 3
- Map Tiles: OpenStreetMap (free)
- No database (reads from JSON file)
- No authentication/authorization
- No rate limiting
- No caching
- All data loaded at once (not suitable for very large datasets)
- Database: Use PostgreSQL/PostGIS or MongoDB for storing detection data
- Vector Tiles: Serve data as vector tiles for better performance with large datasets
- Caching: Add Redis caching for frequently accessed data
- Rate Limiting: Implement rate limiting (e.g., express-rate-limit)
- Authentication: Add JWT or OAuth for API access
- Real-time Updates: Use WebSockets for live data updates
- Map Alternatives: Consider Mapbox for production (better performance, but requires API key)
- Check if port 5000 is already in use
- Verify
backend/data/heatmap_points.jsonexists (run Python script first) - Check Node.js version (requires Node 14+)
- Verify backend is running on port 5000
- Check CORS settings in backend
- Verify
REACT_APP_API_URLenvironment variable
- Check browser console for errors
- Verify data file has valid GeoJSON
- Ensure
leaflet.heatis properly installed - Check that
showHeatmaptoggle is enabled
- Check internet connection (needs OpenStreetMap tiles)
- Verify Leaflet CSS is loaded
- Check browser console for tile loading errors
ISC
This is a prototype/minimal implementation. For production use, consider the improvements listed above.