Django-Mapengine
django-mapengine is a Django app to provide library for maplibre in backend.
This includes
- html templates and JS files for maplibre
- creation of maplibre sources and layers including choropleths,
- provision of multi-vector-tiles from django models,
- distilling of map source views
- basic popups
Requirements
Maplibre must be installed (i.e. via npm) and provided as JS framework
Quick start
-
Add "django_mapengine" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ "...", 'django_mapengine', ]
-
Install maplibre-gl and pubsub-js dependencies by:
npm install maplibre-gl pubsub-js
and copy JS and CSS to your static folder.
-
Include URLs from django_mapengine to your project:
urlpatterns = [ "...", path("map/", include("django_mapengine.urls")), ]
-
Configure map engine by setting zoom levels, regions and styles folder in project settings.py. You can see all possible settings by looking into
django_mapengine.settings.py. Example settings:from django_mapengine import setup MAP_ENGINE_CENTER_AT_STARTUP = [12.537917858911896, 51.80812518969171] MAP_ENGINE_ZOOM_AT_STARTUP = 9 MAP_ENGINE_MAX_BOUNDS = [[11.280733017118229, 51.22918643452503], [13.616574868700604, 52.35515806663738]] MAP_ENGINE_IMAGES = [setup.MapImage("wind", "images/icons/i_wind.png")] MAP_ENGINE_API_MVTS = { "municipality": [ setup.MVTAPI("municipality", "map", "Municipality"), setup.MVTAPI("municipalitylabel", "map", "Municipality", "label_tiles"), ], "results": [setup.MVTAPI("results", "map", "Municipality")] } MAP_ENGINE_API_CLUSTERS = [ setup.ClusterAPI("wind", "map", "WindTurbine"), setup.ClusterAPI("pvroof", "map", "PVroof"), setup.ClusterAPI("pvground", "map", "PVground"), setup.ClusterAPI("hydro", "map", "Hydro"), setup.ClusterAPI("biomass", "map", "Biomass"), setup.ClusterAPI("combustion", "map", "Combustion"), ] MAP_ENGINE_STYLES_FOLDER = "digiplan/static/config/" MAP_ENGINE_POPUPS = ["results"]
-
Add middleware to your middleware setup before Whitenoise middleware (or other static server middleware):
MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django_mapengine.middleware.MapEngineMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", ... ]
-
Create a plain
TemplateViewin views.py (no mixin needed - map data is built per map by the template tag below, at render time):from django.views.generic import TemplateView class MapView(TemplateView): """View to show a map generated by django-mapengine.""" template_name = "map.html"
-
Add maplibre-gl, pubsub-js and the map itself to your template with the
mapengine_maptag. Each call renders one map's container, setup/source JSON and store; the shared JS library files are included automatically, once per page, by the first call:{% load mapengine_tags %} {% block javascript %} {{ block.super }} {% compress js %} <script src="{% static 'vendors/maplibre/js/maplibre-gl.js' %}"></script> <script src="{% static 'vendors/pubsub/js/pubsub.js' %}"></script> {% endcompress %} {% endblock javascript %} {% block css %} {% compress css %} <link href="{% static 'vendors/maplibre/css/maplibre-gl.css' %}" rel='stylesheet'/> {% endcompress %} {% endblock css %} {% block content %} {% mapengine_map "default" %} {% endblock %}To show more than one map side by side, define
MAP_ENGINE_MAPSin settings (a dict of name ->setup.MapConfig, seedjango_mapengine/setup.py) and call the tag once per name, e.g.{% mapengine_map "overview" %}{% mapengine_map "detail" %}. WithoutMAP_ENGINE_MAPS,{% mapengine_map %}(or{% mapengine_map "default" %}) renders a single map built from the flatMAP_ENGINE_*settings above.
User Guides
Metadata
Release files for django-mapengine 6.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_mapengine-6.1.0.tar.gz | 39.7 kB | Without provenance | Details for django_mapengine-6.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_mapengine-6.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_mapengine-6.1.0-py3-none-any.whl |
Total release size: 95.1 kB
Release files / django_mapengine-6.1.0.tar.gz
| Download URL | django_mapengine-6.1.0.tar.gz |
|---|---|
| Size | 39.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0cc2ffdc2de4c93f5c39a508cf070d2ce6a2e9f44601643b8de4e6ab1b69be73
|
|
BLAKE2b-256 checksum How to use checksums |
7ffb221a816c1812604d01dc27fd1e643c9bbfa3de6dbb585838c36301a3d85c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"21.3","id":"virginia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / django_mapengine-6.1.0-py3-none-any.whl
| Download URL | django_mapengine-6.1.0-py3-none-any.whl |
|---|---|
| Size | 55.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ec97a124cd400587ed795d81baca31bcc08118dce6437cc58c52762451565f8
|
|
BLAKE2b-256 checksum How to use checksums |
897ecb189fa0fb1d96ae89e5f6475a987855eaedcb778d70240d37dc0d18c1b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"21.3","id":"virginia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for django-mapengine 6.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.