Skip to content

Commit

Permalink
Make basemap optional
Browse files Browse the repository at this point in the history
  • Loading branch information
henhuy committed Feb 2, 2024
1 parent 6e9cf38 commit eaf939f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 50 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ and the versioning aim to respect [Semantic Versioning](http://semver.org/spec/v

Here is a template for new release sections

## [0.4.0] - 2024-02-02
## [0.15.0] - 2024-02-02
### Changed
- make basemap optional

## [0.14.0] - 2024-02-02
### Added
- toggle legend visibility on choropleth (de)activation

Expand Down
128 changes: 82 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,93 @@ 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 = [
1. Add "django_mapengine" to your INSTALLED_APPS setting like this:
```python
INSTALLED_APPS = [
"...",
'django_mapengine',
]
```
]
```
2. Install maplibre-gl and pubsub-js dependency by:
```shell
npm install maplibre-gl pubsub-js
```
and copy JS and CSS to your static folder.

2. Include URLs from django_mapengine to your project:
```python
urlpatterns = [
"...",
path("map/", include("django_mapengine.urls")),
]
```

3. Configure map engine by setting zoom levels, regions and styles folder in project settings.py.
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 = [core.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"),
]
```python
from django_mapengine import setup

MAP_ENGINE_STYLES_FOLDER = "digiplan/static/config/"
MAP_ENGINE_ZOOM_LEVELS = {
"municipality": core.Zoom(8, 12),
}
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 = [core.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_ZOOM_LEVELS = {
"municipality": core.Zoom(8, 12),
}

MAP_ENGINE_POPUPS = ["results"]
```

5. 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>
{% 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 %}
```

MAP_ENGINE_POPUPS = ["results"]
```
6. 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'}
```

2 changes: 1 addition & 1 deletion django_mapengine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Map Engine init, holds version"""

__version__ = "0.14.0"
__version__ = "0.15.0"
1 change: 0 additions & 1 deletion django_mapengine/templates/django_mapengine/map_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<script src="{% static 'django_mapengine/js/store.js' %}" type="text/javascript"></script>
<script src="{% static 'django_mapengine/js/init.js' %}" type="text/javascript"></script>
<script src="{% static 'django_mapengine/js/map.js' %}" type="text/javascript"></script>
<script src="{% static 'django_mapengine/js/basemaps.js' %}" type="text/javascript"></script>
<script src="{% static 'django_mapengine/js/regions.js' %}" type="text/javascript"></script>
<script src="{% static 'django_mapengine/js/helper.js' %}" type="text/javascript"></script>
<script src="{% static 'django_mapengine/js/legend.js' %}" type="text/javascript"></script>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-mapengine"
version = "0.14.0"
version = "0.15.0"
description = "Map engine for maplibre in django"
authors = ["Hendrik Huyskens <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit eaf939f

Please sign in to comment.