diff options
author | Daniel Schadt <kingdread@gmx.de> | 2022-12-13 22:54:16 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2022-12-13 22:54:16 +0100 |
commit | 4cfe4231bcde25bca06f99c0a23f10005c900feb (patch) | |
tree | 88509013a7e09f003080adb2fa4c85efdce49791 | |
parent | 650e5809e6cc986d87ce2e9f36169936d54c11fd (diff) | |
download | fietsboek-4cfe4231bcde25bca06f99c0a23f10005c900feb.tar.gz fietsboek-4cfe4231bcde25bca06f99c0a23f10005c900feb.tar.bz2 fietsboek-4cfe4231bcde25bca06f99c0a23f10005c900feb.zip |
add support for stamen maps
-rw-r--r-- | doc/administration/configuration.rst | 4 | ||||
-rw-r--r-- | fietsboek/config.py | 13 | ||||
-rw-r--r-- | fietsboek/views/tileproxy.py | 46 |
3 files changed, 63 insertions, 0 deletions
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 <http://maps.stamen.com>`__ 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 <a href="http://stamen.com">Stamen Design</a>, ' + 'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. ' + 'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under ' + '<a href="http://www.openstreetmap.org/copyright">ODbL</a>.', + ), + 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 <a href="http://stamen.com">Stamen Design</a>, ' + 'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. ' + 'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under ' + '<a href="http://www.openstreetmap.org/copyright">ODbL</a>.', + ), + 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 <a href="http://stamen.com">Stamen Design</a>, ' + 'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. ' + 'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under ' + '<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.', + ), +] + 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: |