This project is a lightweight MBTiles server built with Flask, designed to serve vector tiles from an MBTiles database and render them on a web-based map with custom styling. It leverages a thread pool for efficient tile request handling and includes a Leaflet-based frontend for map visualization. The server delivers .pbf (Protocol Buffer Format) tiles and static files, with zoom-dependent styles defined in styles.js for features like water, landcover, roads, and points of interest (POIs). Sample MBTiles files can be downloaded from https://osm.dbtc.link/mbtiles/.
- Flask-based Server: Serves vector tiles via
/tiles/<z>/<x>/<y>.pbf. - Thread Pool: Manages concurrent tile requests with a custom
ThreadPoolclass. - Custom Styling: Defines map feature styles in
styles.jsbased on zoom levels. - MBTiles Support: Queries SQLite-based MBTiles databases and decompresses
.pbftiles. - Static File Serving: Delivers
index.htmland other assets for map display. - Configurable Environment: Uses a
.envfile for database path, host, port, and thread settings.
Dependencies are listed in req.txt:
- Flask (3.1.1)
- blinker (1.9.0)
- click (8.2.1)
- colorama (0.4.6)
- itsdangerous (2.2.0)
- Jinja2 (3.1.6)
- MarkupSafe (3.0.2)
- Werkzeug (3.1.3)
Install them with:
pip install -r req.txt-
Clone the Repository:
git clone <repository-url> cd <repository-directory>
-
Download an MBTiles File:
- Sample MBTiles files are available at
https://osm.dbtc.link/mbtiles/. For example, download2024-12-27-europe.mbtilesor2025-08-02-planet.mbtiles. - Save the file to a
data/directory in the project root (create the directory if it doesn’t exist).
- Sample MBTiles files are available at
-
Configure Environment:
- Edit the
.envfile to set:DATABASE: Path to the MBTiles file (e.g.,data/2024-12-27-europe.mbtiles).HOST: Server host (default:localhost).PORT: Server port (default:8080).MAX_THREAD: Maximum threads (default:10).MAX_QUEUE_SIZE: Maximum task queue size (default:2000).TOKEN: Optional authentication token.
- Edit the
-
Run the Server:
python start.py
The server will start at
http://localhost:8080(or the configured host/port). -
Access the Map:
- Open
http://localhost:8080in a browser to view the demo map using the downloaded MBTiles file. - Static files (
index.html,styles.js) are served from the Flask static folder.
- Open
start.py: Main Flask app for serving tiles and static files.thread_pool.py: Custom thread pool for concurrent tile requests.env_parser.py: Parses.envfor configuration.database_handler.py: Handles SQLite queries and tile decompression.index.html: Leaflet-based frontend for map visualization.styles.js: Custom styles for map features.req.txt: Python dependencies..env: Environment configuration.
The styles.js file defines zoom-dependent styles (0–22) for:
- Water: Blue fill with varying opacity.
- Waterways: Styled lines with labels for rivers/canals.
- Landcover: Colors for forests, grasslands, wetlands, etc.
- Roads: Varying weights/colors by road type and zoom.
- POIs: Colored markers for hospitals, schools, etc., with labels.
- Place Labels: Bold city/town names at higher zooms.
- Access tiles at
/tiles/<z>/<x>/<y>.pbffor map clients. - View the demo map at
/with a downloaded MBTiles file. - Customize
styles.jsto adjust map appearance.
- Ensure downloaded MBTiles files contain valid, decompressible
.pbftiles. - Available sample files at
https://osm.dbtc.link/mbtiles/include regional datasets (e.g., Netherlands, Europe, Africa) and a globalplanetdataset. - Monitor console logs for debugging tile or database issues.
