django-mapengine


Namedjango-mapengine JSON
Version 3.1.0 PyPI version JSON
download
home_pageNone
SummaryMap engine for maplibre in django
upload_time2025-07-28 12:36:20
maintainerNone
docs_urlNone
authorHendrik Huyskens
requires_python<3.12,>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # 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:
   ```python
   INSTALLED_APPS = [
        "...",
        'django_mapengine',
   ]
   ```
2. Install maplibre-gl, pubsub-js and (unfortunately - this shall be removed in the future) jquery dependency by:
   ```shell
   npm install maplibre-gl pubsub-js jquery
   ```
   and copy JS and CSS to your static folder.

3. Include URLs from django_mapengine to your project:
   ```python
   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:

   ```python
   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):
   ```python
   MIDDLEWARE = [
       "django.middleware.security.SecurityMiddleware",
       "django_mapengine.middleware.MapEngineMiddleware",
       "whitenoise.middleware.WhiteNoiseMiddleware",
       ...
   ]
   ```

6. Create a TemplateView in views.py using `views.MapEngineMixin`.
   This will add all data needed for map setup to the view context:
   ```python
   from django.views.generic import TemplateView
   from django_mapengine.views import MapEngineMixin


   class MapView(TemplateView, MapEngineMixin):
       """View to show a map generated by django-mapengine."""

       template_name = "map.html"
   ```

6. Add maplibre-gl, pubsub-js and mapengine JS, CSS and JSONs in template by:
   ```html
   {% 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>
       <script src="{% static 'vendors/jquery/js/jquery.min.js' %}"></script>
     {% endcompress %}
   {% endblock javascript %}

   {%  block inline_javascript %}
     {% include 'django_mapengine/map_json.html' %}
     {% compress js %}
       {% include 'django_mapengine/map_js.html' %}
     {% endcompress %}
   {% endblock %}

   {% block css %}
     {% compress css %}
       <link href="{% static 'vendors/maplibre/css/maplibre-gl.css' %}" rel='stylesheet'/>
     {% endcompress %}
   {% endblock css %}
   ```

7. If you want to integrate basemaps to your map add the following to the corresponding places:
   ```html
   <script src="{% static 'django_mapengine/js/basemaps.js' %}" type="text/javascript"></script>
   {% include 'django_mapengine/map_basemaps.html'}
   ```

# User Guides

- [How to define layers](docs/LAYERS.md)
- [How to enable popups](docs/POPUPS.md)
- [How to set up clusters](docs/CLUSTERS.md)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-mapengine",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.12,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Hendrik Huyskens",
    "author_email": "hendrik.huyskens@rl-institut.de",
    "download_url": "https://files.pythonhosted.org/packages/94/61/15d3cad756d4dc121a9a48f5945124f15459d8f3d92006e0368a16564d95/django_mapengine-3.1.0.tar.gz",
    "platform": null,
    "description": "# Django-Mapengine\n\n`django-mapengine` is a Django app to provide library for maplibre in backend.\nThis includes\n- html templates and JS files for maplibre\n- creation of maplibre sources and layers including choropleths,\n- provision of multi-vector-tiles from django models,\n- distilling of map source views\n- basic popups\n\n## Requirements\n\nMaplibre must be installed (i.e. via npm) and provided as JS framework\n\n## Quick start\n\n1. Add \"django_mapengine\" to your INSTALLED_APPS setting like this:\n   ```python\n   INSTALLED_APPS = [\n        \"...\",\n        'django_mapengine',\n   ]\n   ```\n2. Install maplibre-gl, pubsub-js and (unfortunately - this shall be removed in the future) jquery dependency by:\n   ```shell\n   npm install maplibre-gl pubsub-js jquery\n   ```\n   and copy JS and CSS to your static folder.\n\n3. Include URLs from django_mapengine to your project:\n   ```python\n   urlpatterns = [\n       \"...\",\n       path(\"map/\", include(\"django_mapengine.urls\")),\n   ]\n   ```\n\n4. Configure map engine by setting zoom levels, regions and styles folder in project settings.py.\n   You can see all possible settings by looking into `django_mapengine.settings.py`.\n   Example settings:\n\n   ```python\n   from django_mapengine import setup\n\n   MAP_ENGINE_CENTER_AT_STARTUP = [12.537917858911896, 51.80812518969171]\n   MAP_ENGINE_ZOOM_AT_STARTUP = 9\n   MAP_ENGINE_MAX_BOUNDS = [[11.280733017118229, 51.22918643452503], [13.616574868700604, 52.35515806663738]]\n\n   MAP_ENGINE_IMAGES = [setup.MapImage(\"wind\", \"images/icons/i_wind.png\")]\n\n   MAP_ENGINE_API_MVTS = {\n       \"municipality\":\n           [\n               setup.MVTAPI(\"municipality\", \"map\", \"Municipality\"),\n               setup.MVTAPI(\"municipalitylabel\", \"map\", \"Municipality\", \"label_tiles\"),\n           ],\n       \"results\": [setup.MVTAPI(\"results\", \"map\", \"Municipality\")]\n   }\n\n   MAP_ENGINE_API_CLUSTERS = [\n       setup.ClusterAPI(\"wind\", \"map\", \"WindTurbine\"),\n       setup.ClusterAPI(\"pvroof\", \"map\", \"PVroof\"),\n       setup.ClusterAPI(\"pvground\", \"map\", \"PVground\"),\n       setup.ClusterAPI(\"hydro\", \"map\", \"Hydro\"),\n       setup.ClusterAPI(\"biomass\", \"map\", \"Biomass\"),\n       setup.ClusterAPI(\"combustion\", \"map\", \"Combustion\"),\n   ]\n\n   MAP_ENGINE_STYLES_FOLDER = \"digiplan/static/config/\"\n   MAP_ENGINE_POPUPS = [\"results\"]\n   ```\n\n5. Add middleware to your middleware setup before Whitenoise middleware (or other static server middleware):\n   ```python\n   MIDDLEWARE = [\n       \"django.middleware.security.SecurityMiddleware\",\n       \"django_mapengine.middleware.MapEngineMiddleware\",\n       \"whitenoise.middleware.WhiteNoiseMiddleware\",\n       ...\n   ]\n   ```\n\n6. Create a TemplateView in views.py using `views.MapEngineMixin`.\n   This will add all data needed for map setup to the view context:\n   ```python\n   from django.views.generic import TemplateView\n   from django_mapengine.views import MapEngineMixin\n\n\n   class MapView(TemplateView, MapEngineMixin):\n       \"\"\"View to show a map generated by django-mapengine.\"\"\"\n\n       template_name = \"map.html\"\n   ```\n\n6. Add maplibre-gl, pubsub-js and mapengine JS, CSS and JSONs in template by:\n   ```html\n   {% block javascript %}\n     {{ block.super }}\n     {% compress js %}\n       <script src=\"{% static 'vendors/maplibre/js/maplibre-gl.js' %}\"></script>\n       <script src=\"{% static 'vendors/pubsub/js/pubsub.js' %}\"></script>\n       <script src=\"{% static 'vendors/jquery/js/jquery.min.js' %}\"></script>\n     {% endcompress %}\n   {% endblock javascript %}\n\n   {%  block inline_javascript %}\n     {% include 'django_mapengine/map_json.html' %}\n     {% compress js %}\n       {% include 'django_mapengine/map_js.html' %}\n     {% endcompress %}\n   {% endblock %}\n\n   {% block css %}\n     {% compress css %}\n       <link href=\"{% static 'vendors/maplibre/css/maplibre-gl.css' %}\" rel='stylesheet'/>\n     {% endcompress %}\n   {% endblock css %}\n   ```\n\n7. If you want to integrate basemaps to your map add the following to the corresponding places:\n   ```html\n   <script src=\"{% static 'django_mapengine/js/basemaps.js' %}\" type=\"text/javascript\"></script>\n   {% include 'django_mapengine/map_basemaps.html'}\n   ```\n\n# User Guides\n\n- [How to define layers](docs/LAYERS.md)\n- [How to enable popups](docs/POPUPS.md)\n- [How to set up clusters](docs/CLUSTERS.md)\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Map engine for maplibre in django",
    "version": "3.1.0",
    "project_urls": {
        "Homepage": "https://github.com/rl-institut/django-mapengine",
        "Issues": "https://github.com/rl-institut/django-mapengine/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3f8af2f5691400547dfc89d558ad2d4069b87c30a0358dd3d7ed471aa61317bb",
                "md5": "a33d0d1062a1216c8ed0e32393ea279f",
                "sha256": "7ecac94bd434cbf20690d73d4641c1cdb53eb793fdf2ff2894291e5f0567efee"
            },
            "downloads": -1,
            "filename": "django_mapengine-3.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a33d0d1062a1216c8ed0e32393ea279f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.9",
            "size": 49429,
            "upload_time": "2025-07-28T12:36:18",
            "upload_time_iso_8601": "2025-07-28T12:36:18.901233Z",
            "url": "https://files.pythonhosted.org/packages/3f/8a/f2f5691400547dfc89d558ad2d4069b87c30a0358dd3d7ed471aa61317bb/django_mapengine-3.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "946115d3cad756d4dc121a9a48f5945124f15459d8f3d92006e0368a16564d95",
                "md5": "b3114f9b52b2c7f0eddac3e10da06acd",
                "sha256": "c910b63254e21f9ec3a362c134112f2d21256c0fa01abda4b0a7ed3ba6438924"
            },
            "downloads": -1,
            "filename": "django_mapengine-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b3114f9b52b2c7f0eddac3e10da06acd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.9",
            "size": 35328,
            "upload_time": "2025-07-28T12:36:20",
            "upload_time_iso_8601": "2025-07-28T12:36:20.572813Z",
            "url": "https://files.pythonhosted.org/packages/94/61/15d3cad756d4dc121a9a48f5945124f15459d8f3d92006e0368a16564d95/django_mapengine-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-28 12:36:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rl-institut",
    "github_project": "django-mapengine",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-mapengine"
}
        
Elapsed time: 0.84265s