Skip to content

Commit

Permalink
Merge pull request #53 from rl-institut/hotfix/leaflet-config
Browse files Browse the repository at this point in the history
Fix leaflet config interference
  • Loading branch information
jh-RLI authored Jul 8, 2019
2 parents 8acc78e + ec70a24 commit cec205b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
36 changes: 36 additions & 0 deletions config/leaflet.py
Original file line number Diff line number Diff line change
@@ -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': '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'id': 'mapbox.streets',
'maxZoom': 100,
'minZoom': 9,
}
),
('OSM B&W', 'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png',
{'attribution': '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'minZoom': 9,
}
),
('OSM', 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{'attribution': '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'minZoom': 9,
}),
('OpenTopoMap', 'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
{'attribution': 'Data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, Display: &copy <a href="http://opentopomap.org">OpenTopoMap</a> <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'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,
}
32 changes: 0 additions & 32 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'id': 'mapbox.streets',
'maxZoom': 100,
'minZoom': 9,
}
),
('OSM B&W', 'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png',
{'attribution': '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'minZoom': 9,
}
),
('OSM', 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{'attribution': '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'minZoom': 9,
}),
('OpenTopoMap', 'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
{'attribution': 'Data: &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, Display: &copy <a href="http://opentopomap.org">OpenTopoMap</a> <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
'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,
}
2 changes: 1 addition & 1 deletion templates/WAM_APP_FRED/test_map_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ <h2 class="tabs-title__head">Feedin-Time Series</h2>
<i class="icon ion-android-options"></i>
</button>

{% leaflet_map "map" callback="window.map_init_basic" %}
{% leaflet_map "map" callback="window.map_init_basic" settings_overrides=leaflet_config%}

</div>
</main>
Expand Down
8 changes: 6 additions & 2 deletions views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render

from WAM_APP_FRED.config.leaflet import LEAFLET_CONFIG
# Create your views here.


Expand All @@ -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}
)

0 comments on commit cec205b

Please sign in to comment.