Level 1 Team Project
Air Quality Monitoring Simulator

Step 1: Project Setup
Install Vite + React
2. Clean up the boilerplate // Delete unnecessary files in 'src' and keep 'main.jsx', 'App.jsx', and 'App.css'.
Add style.css file (external stylesheet)
// Create a new file in 'src/style.css'. We'll move common styles here for better structure.
Step 2: Setup App.jsx (you already have this, we will improve a bit)
Step 3: Improve Styling (style.css)
Create src/style.css at src foler.
We would like to expand our app to include the following functionality:
🎯 Integrate Leaflet.js for real maps.
🔌 Use OpenAQ API for real-time air quality data.
🎨 Add dynamic map markers and city info popup.
🔍 Add search box for better UX.
Step 4. Install Leaflet packages and Include Leaflet CSS
In your index.html, inside <head>, add:
Step 5: Update App.jsx
OurApp.jsx is now fully set up to:
Import Leaflet components
Dynamically place markers based on city data
Show popup with city name, AQI, and country
Step 6: Improve style.css for Map
Our external CSS now ensures:
Map height and width are controlled
Inputs and buttons remain pretty
Responsive layout is prepared
Challenge: Next Enhancements (Highly Recommended!)
🚀 Auto-refresh AQI data (Simulate or connect to real API)
🎨 Custom map styling (e.g., dark mode tiles)
🔍 Search bar to quickly find cities
🌐 Mobile responsiveness
🧩 Cluster markers for crowded areas
Step 6. Install dependencies and Add Leaflet CSS
In 'index.html' inside , add: Add CDN link in index.html.
Step 7: Update App.jsx with Real-Time AQI Simulation & API Integration
When we run app, we encounter the following issues:
Solution: Create Your Own Local Backend Proxy (Best Practice)
If you want to practice backend/frontend separation (good for your portfolio), do this:
Step 1: Create a simple Express server
In your project root, run:
Create a new file at root directory: server.js
Step 2: Update your React App.jsx
Change:
To:
Step 3: Run your backend and frontend
In one terminal, run:
In another terminal, run your React app:
Solution 2: Local Mock Data (For Safe Classroom Project)
We're already simulating AQI, and to avoid unstable external APIs, let’s mock the data locally.
Step 1: Update your serverMock.js like this:
serverMock.js like this:Switch map mode between Dark Mode and Light Mode
We will:
Add a toggle button to switch between dark and light map styles.
Update your
<TileLayer />component to dynamically use the selected mode.
Step 1: Add State for Map Mode
In your App.jsx, at the top inside your component, add state for map mode:
Step 2: Add Toggle Button
Above your map (maybe below filters), add a button to switch modes:
Step 3: Update TileLayer to Use Dynamic Map Style
Now go to your <TileLayer /> component and replace the static URL with a dynamic one:
Now when you click the button:
🌗 Dark mode: CartoDB dark tiles.
🌞 Light mode: OpenStreetMap standard tiles.
✅ Seamless switch!
✅ Works even while map is active.
Output:

Last updated