Overview
The map generation process (mapita5.py:40-62) takes Excel data and creates an interactive HTML map with markers for each historical content location.
Step-by-Step Process
1. Initialize Dependencies
folium: Creates Leaflet.js mapspandas: Reads Excel files and processes datarequests: Downloads images from URLsos: File system operations
2. Setup Image Cache
imagenes/ directory to cache downloaded thumbnails. This improves performance and ensures the map works offline.
Location: mapita5.py:6-8
3. Load Data Source
mapita5.py:11
4. Parse Coordinates
The coordinate parsing function handles the “lat,lon” format:mapita5.py:14-20
Coordinate Format:
- Format:
"latitude,longitude" - Example:
"28.1235,-15.4362" - Decimal degrees (WGS84 coordinate system)
- Negative values for West longitude and South latitude
- Returns
(None, None)for invalid coordinates - Prints error message to console
- Skips invalid locations during map generation
5. Download and Cache Images
mapita5.py:23-37
Features:
- Streams images in 1KB chunks to handle large files
- Saves with sequential naming:
imagen_0.jpg,imagen_1.jpg, etc. - Returns local file path for use in HTML
- Handles network errors gracefully
6. Create Base Map
mapita5.py:40
Configuration:
location=[28.0, -15.0]: Center on Canary Islandszoom_start=6: Show entire archipelago- Uses default OpenStreetMap tiles
7. Add Markers with Popups
mapita5.py:43-58
Process:
- Iterate through each row in the Excel data
- Parse coordinates from the
Localizacióncolumn - Download and cache the thumbnail image
- Create HTML popup content with:
- Title (first word of reel text)
- Thumbnail image (200px width, auto height)
- Link to Instagram post
- Create Folium marker with popup (300px max width)
- Add marker to the map
- Skips rows with invalid coordinates
- Skips markers if image download fails
- Ensures robust map generation even with incomplete data
8. Save HTML Output
mapita5.py:61-62
Generates a self-contained HTML file with:
- Embedded Leaflet.js library
- Map configuration and markers
- Relative paths to cached images
- Interactive JavaScript controls
Generated Output
File Structure
HTML Map Features
- Interactive panning: Drag to explore
- Zoom controls: Mouse wheel or +/- buttons
- Marker clusters: Automatic grouping at low zoom levels (if enabled)
- Clickable markers: Open popups with content
- Responsive design: Works on desktop and mobile
Performance Considerations
Image Caching
Images are downloaded once and reused:- First run: Downloads all images (slower)
- Subsequent runs: Uses cached images (faster)
- Storage: ~100-500KB per image
Large Datasets
For maps with many markers:- Consider marker clustering plugins
- Optimize image sizes before upload
- Use lazy loading for popups
- Filter data by region or time period
Error Handling
The script handles common issues:| Issue | Behavior |
|---|---|
| Invalid coordinates | Skip marker, print error |
| Failed image download | Skip marker, print error |
| Missing Excel columns | Raise exception |
| Network timeout | Skip image, continue processing |
Running the Script
Basic Execution
Prerequisites
Install required packages:Expected Output
"Error al procesar la ubicación: ..."- Invalid coordinate format"No se pudo descargar la imagen: ..."- HTTP error (404, 403, etc.)"Error al descargar la imagen: ..."- Network or file system error
Next Steps
- Customization Guide - Learn how to customize markers, popups, and map styling