An interactive Flask application that lets you plan routes across Phnom Penh on top of OpenStreetMap data. The backend assembles and caches the city road network with OSMnx/NetworkX, while the frontend renders a mobile-friendly Leaflet interface with address search, live geolocation and multiple vehicle profiles.
- Interactive Leaflet map with draggable markers, Nominatim-powered address search, and location autofill.
- Multiple vehicle presets (motorbike, car, tuk-tuk, bicycle) that apply different travel-time heuristics.
- Ranked alternative routes with distance and ETA summaries rendered in a glassmorphic side panel optimised for desktop and mobile.
- Graph caching on disk so the OpenStreetMap network is downloaded only once.
- Clean separation between Flask endpoints, routing helpers, and static assets.
- Python 3.11 or newer (3.10+ should work but is not regularly tested).
- System packages required by
osmnxandshapely(for examplegeos,proj,libspatialindex,rtreeon many Linux distributions). - Internet access on the first run so the OSM road graph and Nominatim search results can be fetched.
# 1. Create and activate a virtual environment
python3 -m venv .venv
source .venv/bin/activate
# 2. Install dependencies
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
# 3. Run the development server
flask --app app --debug runOpen http://127.0.0.1:5000 in your browser. The first route request may take a minute while OSMnx downloads and caches the Phnom Penh road graph to kmap/cache/graph_pp.graphml.
- Choose a starting point by typing coordinates, selecting a search result, clicking the map, or using the “📍” button to read your device position.
- Search for a destination or tap the map to drop the target marker; the planner automatically computes up to three ranked routes.
- Switch vehicle types to re-run routing with different travel-time profiles.
- On mobile, collapse the planner panel with the toggle button to explore the map.
app.py Flask entrypoint exposing / and /route
kmap/routing.py Road graph loading, caching, and route calculation
static/ Leaflet map client (JavaScript, CSS)
templates/index.html Main HTML shell
cache/, kmap/cache/ OSMNX HTTP cache and saved road graph
tests/ Pytest scaffold (add tests here)
Activate your virtual environment and run:
pytestPopulate tests/ with unit or integration cases as you extend the planner.
- Road network data © OpenStreetMap contributors, served via OSMnx.
- Address search powered by Nominatim; please respect the usage policy if you deploy publicly.
Issues and pull requests that improve routing heuristics, UI polish, or deployment readiness are welcome. When submitting changes, update documentation and add tests where practical.