What it does:
The script reads two CSV files (e.g. a list of schools and a list of hospitals) from a data/ folder, builds an interactive leaflet map with a separate layer for each file, and writes the result to output/map.html.
| Tool | Minimum version |
|---|---|
| Python | 3.8+ (python3 command) |
| git (optional) | any recent version |
Unix‑like shell (macOS / Linux) or Windows terminal that supports source (Git Bash, WSL, PowerShell with activation script) |
# 1️⃣ Create a virtual environment in the project root
python3 -m venv .venv
# 2️⃣ Activate the virtual environment
source .venv/bin/activate # macOS / Linux
# .venv\Scripts\activate # Windows PowerShell / CMD
# 3️⃣ Install all required Python packages
pip install -r requirements.txtAfter activation your prompt will be prefixed with
(.venv), confirming that anypython/pipcommand now runs inside the isolated environment.
deactivate# Ensure the virtual environment is active
source .venv/bin/activate # (or .venv\Scripts\activate on Windows)
# Run the script
python two_layer_map.pyWhat happens
- The script looks for exactly two CSV files inside the folder
data/. - Each CSV must contain the columns
latitude,longitude, and a column that will be shown in the popup (by default it looks for a column namedname). - Two map layers are created – one for each CSV – and a Leaflet layer control is added so the user can toggle the layers on/off.
- The generated interactive map is saved as
output/map.html(theoutput/directory is created automatically if it does not exist).
Tip:
- If you want to use a different column for the popup, rename the column to
nameor edit the script’sNAME_COLUMNconstant.- The script prints a short summary (rows loaded, output path, etc.) to the console.
| Column name | Required? | Description |
|---|---|---|
latitude |
✅ | Decimal degrees, e.g. 40.7128 |
longitude |
✅ | Decimal degrees, e.g. -74.0060 |
name |
✅ | Text shown in the marker popup/tooltip (any other column name can be used by renaming it to name or adjusting the script) |
| … | optional | Any additional columns are ignored by the script but can be useful for later extensions. |
Example (schools.csv)
latitude,longitude,name
40.730610,-73.935242,PS 101
40.712776,-74.005974,PS 102Place both CSV files in the data/ directory before running the script.
The final artifact is an HTML file that can be opened in any modern web browser:
output/
└── map.html
Open it directly:
open output/map.html # macOS
xdg-open output/map.html # Linux
start output\map.html # Windowspython3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && python two_layer_map.py