Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preset Stamen tile file extension, opacity #2202

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,44 @@ class Stamen(GoogleWTS):
"""

def __init__(self, style='toner',
desired_tile_form='RGB', cache=False):
desired_tile_form=None, cache=False):

# preset layer configuration
layer_config = {
'terrain': {'extension': 'png', 'opaque': True},
'terrain-background': {'extension': 'png', 'opaque': True},
'terrain-labels': {'extension': 'png', 'opaque': False},
'terrain-lines': {'extension': 'png', 'opaque': False},
'toner-background': {'extension': 'png', 'opaque': True},
'toner': {'extension': 'png', 'opaque': True},
'toner-hybrid': {'extension': 'png', 'opaque': False},
'toner-labels': {'extension': 'png', 'opaque': False},
'toner-lines': {'extension': 'png', 'opaque': False},
'toner-lite': {'extension': 'png', 'opaque': True},
'watercolor': {'extension': 'jpg', 'opaque': True},
}

# get layer information from dict
layer_info = layer_config.get(
style, {'extension': '.png', 'opaque': True})

# use optional desired_tile_form input if available
# otherwise, use preset value based on the layer name
if desired_tile_form is None:
if layer_info['opaque']:
desired_tile_form = 'RGB'
else:
desired_tile_form = 'RGBA'

super().__init__(desired_tile_form=desired_tile_form,
cache=cache)
self.style = style
self.extension = layer_info['extension']

def _image_url(self, tile):
x, y, z = tile
return f'http://tile.stamen.com/{self.style}/{z}/{x}/{y}.png'
return 'http://tile.stamen.com/' + \
f'{self.style}/{z}/{x}/{y}.{self.extension}'


class MapboxTiles(GoogleWTS):
Expand Down