Convert a directory of GPX files into a static website with an interactive map
npm install gpx-mapperA Node.js CLI tool that converts a directory of GPX files into a static website with an interactive map. Perfect for cycling clubs to publish their frequent routes.
- Interactive Map: Routes displayed on OpenStreetMap vector tiles using MapLibre GL JS
- Responsive Design: Two-pane layout on desktop (sidebar + map), dropdown selector on mobile
- Route Details: Shows distance (km) and elevation gain (m) for each route
- Shareable URLs: Link directly to specific routes
- GPX Downloads: Each route includes a download link to the original GPX file
- Unique Route Colors: Each route gets a distinct color for easy identification
- Static Output: Generates a standalone website that can be hosted anywhere
``bash`
npm install
`bash`
npx gpx-mapper
| Option | Description | Default |
|--------|-------------|---------|
| -t, --title
| Site title | "Route Map" |
| -V, --version | Show version number | |
| -h, --help | Show help | |$3
`bash
Basic usage
npx gpx-mapper ./gpx ./distWith custom title
npx gpx-mapper ./gpx ./dist --title "EGCC Routes"
`Output Structure
`
dist/
├── index.html # Main HTML page
├── app.js # Client-side JavaScript
├── routes.json # Route data (loaded at runtime)
└── gpx/ # Copied GPX files for download
├── route1.gpx
├── route2.gpx
└── ...
`Viewing the Generated Site
The generated site must be served via HTTP (not opened directly as a file) because it fetches
routes.json at runtime.`bash
Using npx serve
npx serve ./distOr any other static file server
python -m http.server 8000 --directory ./dist
`How It Works
1. Build Time: The CLI parses all GPX files in the input directory, extracts route names, coordinates, distances, and elevation data
2. Output: Generates a static website with the route data stored in
routes.json
3. Runtime: The client-side JavaScript fetches routes.json and renders routes on the mapGPX File Requirements
- Standard GPX 1.1 format
- Must contain at least one
(track) with (track points)
- Route name is extracted from metadata (falls back to filename)
- Elevation data () is optional but enables elevation gain displayBrowser Support
Works in all modern browsers that support:
- ES6+ JavaScript
- WebGL (for MapLibre GL JS)
- Fetch API
Dependencies
$3
- commander - CLI argument parsing
- gpxparser - GPX file parsing
- he` - HTML entity decodingMIT