Skip to main content

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

  1. Add "django_mapengine" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
         "...",
         'django_mapengine',
    ]
    
  2. Install maplibre-gl and pubsub-js dependencies by:

    npm install maplibre-gl pubsub-js
    

    and copy JS and CSS to your static folder.

  3. Include URLs from django_mapengine to your project:

    urlpatterns = [
        "...",
        path("map/", include("django_mapengine.urls")),
    ]
    
  4. 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"]
    
  5. 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",
        ...
    ]
    
  6. Create a plain TemplateView in 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"
    
  7. Add maplibre-gl, pubsub-js and the map itself to your template with the mapengine_map tag. 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_MAPS in settings (a dict of name -> setup.MapConfig, see django_mapengine/setup.py) and call the tag once per name, e.g. {% mapengine_map "overview" %}{% mapengine_map "detail" %}. Without MAP_ENGINE_MAPS, {% mapengine_map %} (or {% mapengine_map "default" %}) renders a single map built from the flat MAP_ENGINE_* settings above.

User Guides

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_mapengine-6.0.0.tar.gz (39.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_mapengine-6.0.0-py3-none-any.whl (55.3 kB view details)

Uploaded Python 3

File details

Details for the file django_mapengine-6.0.0.tar.gz.

File metadata

  • Download URL: django_mapengine-6.0.0.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for django_mapengine-6.0.0.tar.gz
Algorithm Hash digest
SHA256 195a2f799867eed1d4b26db25502ced9271e8ad23cc7119d94e00d93e9a9797e
MD5 fd27898b8ff3f7faef39d7f6c7f94739
BLAKE2b-256 650aa9ed5648b864d28db988dbe13f3226c3efd8e6089623a19348a30dc762cb

See more details on using hashes here.

File details

Details for the file django_mapengine-6.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_mapengine-6.0.0-py3-none-any.whl
  • Upload date:
  • Size: 55.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for django_mapengine-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 589786c599ebbbe98233402ff6bee1f8c013f9712bfc3fedd3e22a1e679c9fb1
MD5 4b728cb5db3d17ceca0c00aab8112641
BLAKE2b-256 8f8f3c00c6ac1cae8931308a98d51f87a8ef19cd8f15e4660a4bd8ab5b48f326

See more details on using hashes here.

Release history Release notifications | RSS feed

6.1.0

2 files

This release

6.0.0 This release

2 files

5.1.0

2 files

5.0.3

2 files

5.0.2

2 files

5.0.1

2 files

4.1.0

2 files

4.0.0

2 files

3.3.0

1 file

3.2.1

2 files

3.2.0

2 files

3.1.0

2 files

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.3.0

2 files

2.2.10

2 files

2.2.9

2 files

2.2.8

2 files

2.2.7

2 files

2.2.6

2 files

2.2.5

2 files

2.2.4

2 files

2.2.3

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.8.2

2 files

1.8.1

2 files

1.8.0

2 files

1.7.0

2 files

1.6.1

2 files

1.6.0

2 files

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.0

2 files

1.2.2

2 files

1.2.1

2 files

1.1.0

2 files

1.0.0

2 files

0.19.0

2 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