From 4cfe4231bcde25bca06f99c0a23f10005c900feb Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 13 Dec 2022 22:54:16 +0100 Subject: add support for stamen maps --- doc/administration/configuration.rst | 4 ++++ fietsboek/config.py | 13 ++++++++++ fietsboek/views/tileproxy.py | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/doc/administration/configuration.rst b/doc/administration/configuration.rst index 5f0e3d4..e77e3cc 100644 --- a/doc/administration/configuration.rst +++ b/doc/administration/configuration.rst @@ -168,6 +168,10 @@ users will be able to use the Thunderforest maps (to protect your quota), this can be changed by setting ``thunderforest.access = public`` (default is "restricted"). +You can enable `Stamen `__ support by setting +``stamen.maps`` to the desired maps, e.g. ``stamen.maps = toner terrain +watercolor``. + You can add custom tile layers in the following way: .. code:: ini diff --git a/fietsboek/config.py b/fietsboek/config.py index 41f6a64..d95469c 100644 --- a/fietsboek/config.py +++ b/fietsboek/config.py @@ -193,6 +193,9 @@ class Config(BaseModel): thunderforest_access: LayerAccess = Field(LayerAccess.RESTRICTED, alias="thunderforest.access") """Thunderforest access restriction.""" + stamen_maps: PyramidList = Field([], alias="stamen.maps") + """Enabled stamen maps.""" + disable_tile_proxy: bool = Field(False, alias="fietsboek.tile_proxy.disable") """Disable the tile proxy.""" @@ -216,6 +219,16 @@ class Config(BaseModel): raise ValueError(f"Unknown mailing scheme {parsed.scheme}".strip()) return value + @validator("stamen_maps") + def _known_stamen(cls, value): + """Ensures that the stamen maps are known.""" + maps = set(value) + known_maps = {"toner", "terrain", "watercolor"} + bad_maps = maps - known_maps + if bad_maps: + raise ValueError("Unknown stamen maps: " + ", ".join(bad_maps)) + return value + def derive_secret(self, what_for): """Derive a secret for other parts of the application. diff --git a/fietsboek/views/tileproxy.py b/fietsboek/views/tileproxy.py index f0612dc..61747d4 100644 --- a/fietsboek/views/tileproxy.py +++ b/fietsboek/views/tileproxy.py @@ -174,6 +174,45 @@ DEFAULT_TILE_LAYERS = [ ), ] +STAMEN_LAYERS = [ + TileSource( + "stamen-toner", + "Stamen Toner", + "https://stamen-tiles.a.ssl.fastly.net/toner/{z}/{x}/{y}.png", + LayerType.BASE, + 12, + LayerAccess.PUBLIC, + f'{_jb_copy} | Map tiles by Stamen Design, ' + 'under CC BY 3.0. ' + 'Data by OpenStreetMap, under ' + 'ODbL.', + ), + TileSource( + "stamen-terrain", + "Stamen Terrain", + "https://stamen-tiles.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png", + LayerType.BASE, + 12, + LayerAccess.PUBLIC, + f'{_jb_copy} | Map tiles by Stamen Design, ' + 'under CC BY 3.0. ' + 'Data by OpenStreetMap, under ' + 'ODbL.', + ), + TileSource( + "stamen-watercolor", + "Stamen Watercolor", + "https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png", + LayerType.BASE, + 12, + LayerAccess.PUBLIC, + f'{_jb_copy} | Map tiles by Stamen Design, ' + 'under CC BY 3.0. ' + 'Data by OpenStreetMap, under ' + 'CC BY SA.', + ), +] + TTL = datetime.timedelta(days=7) """Time to live of cached tiles.""" @@ -280,6 +319,7 @@ def extract_tile_layers(config): """ layers = [] layers.extend(_extract_thunderforest(config)) + layers.extend(_extract_stamen(config)) layers.extend(_extract_user_layers(config)) return layers @@ -312,6 +352,12 @@ def _extract_thunderforest(config): ) +def _extract_stamen(config): + layers = {layer.key: layer for layer in STAMEN_LAYERS} + for name in config.stamen_maps: + yield layers[f"stamen-{name}"] + + def _extract_user_layers(config): # Any other custom maps for layer in config.tile_layers: -- cgit v1.2.3