From 320b421ec4a710f1da8f2ce4b70bcde0ff7a5fce Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Fri, 5 Jul 2019 11:34:28 +0200 Subject: [PATCH 1/3] Move leaflet config in a dedicated folder This is needed to avoid the interference of leaflet config between apps --- config/leaflet.py | 36 ++++++++++++++++++++++++++++++++++++ settings.py | 32 -------------------------------- 2 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 config/leaflet.py diff --git a/config/leaflet.py b/config/leaflet.py new file mode 100644 index 0000000..5965ed4 --- /dev/null +++ b/config/leaflet.py @@ -0,0 +1,36 @@ +# Leaflet config: variable "LEAFLET_CONFIG" moved from settings.py to here +# since it conflicts with other apps using django-leaflet package. +# The leaflet config is now served via views.MapView() (uses settings override +# feature of django-leaflet) +# Related issue: https://github.com/rl-institut/WAM/issues/74 + +LEAFLET_CONFIG = { + 'TILES': [('Streets', 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', + {'attribution': '© OpenStreetMap contributors, CC-BY-SA', + 'id': 'mapbox.streets', + 'maxZoom': 100, + 'minZoom': 9, + } + ), + ('OSM B&W', 'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', + {'attribution': '© OpenStreetMap contributors, CC-BY-SA', + 'minZoom': 9, + } + ), + ('OSM', 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', + {'attribution': '© OpenStreetMap contributors, CC-BY-SA', + 'minZoom': 9, + }), + ('OpenTopoMap', 'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', + {'attribution': 'Data: © OpenStreetMap contributors, Display: © OpenTopoMap CC-BY-SA', + 'minZoom': 9, + }) + ], + # Germany center (center = long/2 and lat/2) + 'DEFAULT_CENTER': (53.4554, 9.6211), + 'DEFAULT_ZOOM': 10, + 'MIN_ZOOM': 3, + 'MAX_ZOOM': 1000, + 'RESET_VIEW': False, + 'NO_GLOBALS': False, +} \ No newline at end of file diff --git a/settings.py b/settings.py index 8e5c08f..79f25cb 100644 --- a/settings.py +++ b/settings.py @@ -4,35 +4,3 @@ # List here the javascript packages needed for this app INSTALLED_APPS = ['leaflet'] -LEAFLET_CONFIG = { - # conf here - - 'TILES': [('Streets', 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', - {'attribution': '© OpenStreetMap contributors, CC-BY-SA', - 'id': 'mapbox.streets', - 'maxZoom': 100, - 'minZoom': 9, - } - ), - ('OSM B&W', 'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', - {'attribution': '© OpenStreetMap contributors, CC-BY-SA', - 'minZoom': 9, - } - ), - ('OSM', 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', - {'attribution': '© OpenStreetMap contributors, CC-BY-SA', - 'minZoom': 9, - }), - ('OpenTopoMap', 'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', - {'attribution': 'Data: © OpenStreetMap contributors, Display: © OpenTopoMap CC-BY-SA', - 'minZoom': 9, - }) - ], - # Germany center (center = long/2 and lat/2) - 'DEFAULT_CENTER': (53.4554, 9.6211), - 'DEFAULT_ZOOM': 10, - 'MIN_ZOOM': 3, - 'MAX_ZOOM': 1000, - 'RESET_VIEW': False, - 'NO_GLOBALS': False, -} From ef877700391b0d19acf213d00aa7cdd63e319f9b Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Fri, 5 Jul 2019 11:42:20 +0200 Subject: [PATCH 2/3] Override the settings in the map template --- templates/WAM_APP_FRED/test_map_layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/WAM_APP_FRED/test_map_layout.html b/templates/WAM_APP_FRED/test_map_layout.html index 6a2dd8f..2137bf1 100644 --- a/templates/WAM_APP_FRED/test_map_layout.html +++ b/templates/WAM_APP_FRED/test_map_layout.html @@ -197,7 +197,7 @@

Feedin-Time Series

- {% leaflet_map "map" callback="window.map_init_basic" %} + {% leaflet_map "map" callback="window.map_init_basic" settings_overrides=leaflet_config%} From 530302af1ebfc5a222cc322ea13f3db2ad255480 Mon Sep 17 00:00:00 2001 From: Bachibouzouk Date: Mon, 8 Jul 2019 09:35:09 +0200 Subject: [PATCH 3/3] Pass the leaflet config to the view as context --- views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/views.py b/views.py index 69d30c1..5c34230 100644 --- a/views.py +++ b/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render - +from WAM_APP_FRED.config.leaflet import LEAFLET_CONFIG # Create your views here. @@ -8,4 +8,8 @@ def fred_map(request): def webgui_test(request): - return render(request, 'WAM_APP_FRED/test_map_layout.html') + return render( + request, + 'WAM_APP_FRED/test_map_layout.html', + context={'leaflet_config': LEAFLET_CONFIG} + )