From 45e6b84b818b1d729e558e811a3020d8fd3ca3b9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 17 Nov 2022 23:01:50 +0100 Subject: add a shortcut for Thunderforest maps Now, we can add Thunderforest maps with thunderforest.api_key = ... thunderforest.maps = cycling ... --- fietsboek/__init__.py | 2 ++ fietsboek/views/tileproxy.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/fietsboek/__init__.py b/fietsboek/__init__.py index 21674f5..7aede7b 100644 --- a/fietsboek/__init__.py +++ b/fietsboek/__init__.py @@ -72,6 +72,8 @@ def main(global_config, **settings): settings.get('available_locales', 'en')) settings['fietsboek.pages'] = aslist( settings.get('fietsboek.pages', '')) + settings['thunderforest.maps'] = aslist( + settings.get('thunderforest.maps', '')) settings['fietsboek.default_tile_layers'] = aslist( settings.get('fietsboek.default_tile_layers', 'osm satellite osmde opentopo topplusopen opensea cycling hiking')) diff --git a/fietsboek/views/tileproxy.py b/fietsboek/views/tileproxy.py index 42e1a67..ff68e30 100644 --- a/fietsboek/views/tileproxy.py +++ b/fietsboek/views/tileproxy.py @@ -263,6 +263,24 @@ def extract_tile_layers(settings): :rtype: list[TileSource] """ layers = [] + # Thunderforest Shortcut! + tf_api_key = settings.get("thunderforest.api_key") + if tf_api_key: + tf_access = LayerAccess(settings.get("thunderforest.access", "restricted")) + tf_attribution = ' | '.join([ + _jb_copy, + _href("https://www.thunderforest.com/", "Thunderforest"), + _href("https://www.openstreetmap.org/", "OpenStreetMap"), + ]) + for tf_map in settings["thunderforest.maps"]: + url = (f"https://tile.thunderforest.com/{tf_map}/" + f"{{z}}/{{x}}/{{y}}.png?apikey={tf_api_key}") + layers.append(TileSource( + f"tf-{tf_map}", f"TF {tf_map.title()}", url, + LayerType.BASE, 22, tf_access, tf_attribution, + )) + + # Any other custom maps for key in settings.keys(): match = re.match("^fietsboek\\.tile_layer\\.([A-Za-z0-9_-]+)$", key) if not match: -- cgit v1.2.3