Skip to main content

Django Tiles GL

Integrated Django Vector Tile Server based on mbtiles.

Description

Simple app to serve Mabpox Vector Tiles directly from MBTiles files via Django views.

Django Tiles has a minimal dependencies. It does not require GeoDjano or any other libraries. Its only dependency is Django itself.

Django Tiles GL does not create raster tiles. It may only be used with map libraries that support to render vector tiles like MapLibre or OpenLayers.

Django Tiles GL contains the OSM Bright map style which can be used to render Vector Tiles following the OpenMapTiles vector tile schema.

Note that this default style is using OpenSans fonts which does only contain Latin, Greek and Cyrillic alphabets.

Other tile schemes are possible by creating a custom map style specification and referencing Django Tiles GL TileJSON endpoint as a source.

Usage

See the demo Django application for a simple usage example.

Setup

  • Add django_tiles_gl to you INSTALLED_APPS setting.
  • Add django_tiles_gl.urls to your url patterns. For example with the tiles prefix:
    urlpatterns = [
        ...
        path("tiles/", include("django_tiles_gl.urls")),
    ]
    
  • Set path to your MBTiles files in you application settings.
    MBTILES_DATABASE = BASE_DIR / "demo" / "data" / "berlin.mbtiles"
    
  • Optionally set the default center to be set on the default map style.
    MBTILES_CENTER = [13.4, 52.5, 13]   # [longitude, latitude, zoom]
    
  • Optionally force absolute urls to use SSL by prefixing them with "https://". This might be required if you app is running behind a reverse proxy and you are not able to set SECURE_PROXY_SSL_HEADER from the SSL enabled proxy server.
    MBTILES_FORCE_SSL = True
    

Views

To render a map you have to include a JavaScript mapping library and refer to the tile endpoint or the default integrated style.

Django Tiles GL provides the following endpoints:

  • {% url 'django_tiles_gl:openmaptiles_style' %} - Default OpenMapTiles style defintion using the OSM Bright map style.
  • {% url 'django_tiles_gl:tilejson' %} - TileJSON describing the configured MBTiles files and providing the correct tile urls.
  • {% url 'django_tiles_gl:tile' x y z %} - Actual tile endpoint, returning vector data in the PBF format.

Django Tiles GL is bundles with MapLibre and provides a template tag for easy inclusion. A minimal working example has to contain the following defintions:

{% load tiles_gl_tags %}
<!DOCTYPE html>
<html>
<head>
    {% maplibre_head %}

    <style>
        body { margin:0; padding:0; }
        #map { position:absolute; top:0; bottom:0; width:100%; }
    </style>
</head>
<body>

<div id='map'></div>

<script>
var map = new maplibregl.Map({
	container: 'map',
	style: '{% url 'django_tiles_gl:openmaptiles_style' %}',
});
</script>

</body>
</html>

Data / MBTiles generation

There are mutiple tools to generate valid MBTiles databases. The easiest to use with Django Tiles GL is OpenMapTiles as it is compatible with the bundled default style.

For a quickstart you may generate the MbTiles for an area with the following commands:

git clone https://github.com/openmaptiles/openmaptiles.git
cd openmaptiles
./quickstart.sh <area>

Fo further information and optiones see https://github.com/openmaptiles/openmaptiles

Further Topics

Caching

It is advised setup a caching proxy for the tile endpoint. Please refer to you HTTP servers documentation. For example the nginx proxy cache config

Other Django tile server solutions

  • django-geojson-tiles - Generates GeoJSON tiles from a GeoDjango model. No MBTiles support. Not to be used as a base layer.

  • django-vectortiles - Generates Vector Tile layers from GeoDjango. No MBTiles support. Not to be used as a base layer.

  • django-mbtiles - Uses MBTiles to generate rastered tiles and UTFGrid. Does not support modern vector tiles. Strong inspiration for this project.

Metadata

Release files for django-tiles-gl 0.3.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-tiles-gl 0.3.9
File Size Uploaded
django_tiles_gl-0.3.9.tar.gz 2.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-tiles-gl 0.3.9
File Interpreter ABI Platform
django_tiles_gl-0.3.9-py3-none-any.whl Python 3 none any Details

Total release size: 5.6 MB

Release files / django_tiles_gl-0.3.9.tar.gz

Download URL django_tiles_gl-0.3.9.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
3e3010c0a2925e50f20f49be5e5253e277176b3d3e2ca3fe0fa0ea861fc336a7
BLAKE2b-256 checksum
How to use checksums
c4792c6063644b5cfc39a408417dfd1e3d5b9b73c09aa26aef10a9ad961801d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.2 Linux/6.5.0-1025-azure

Release files / django_tiles_gl-0.3.9-py3-none-any.whl

Download URL django_tiles_gl-0.3.9-py3-none-any.whl
Size 3.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f110727cdee9d67001ffff29dbd3c71ce84f40dfcea6a8eadcfc97bd3d1e387c
BLAKE2b-256 checksum
How to use checksums
18c4e45cf2c8c0b4885675fb305305626af3e76f751d5a04a16acc6fc143f803
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.2 Linux/6.5.0-1025-azure

Release history Release notifications | RSS feed

This release

0.3.9 This release

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page