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

Refactor: check if place holders in custom tms url contains any space within #281

Merged
merged 2 commits into from
Aug 5, 2024
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
10 changes: 9 additions & 1 deletion osm_fieldwork/basemapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,16 @@ def customTMS(self, url: str, is_oam: bool = False, is_xy: bool = False):
# FIXME handle other formats for custom TMS
suffix = "jpg"

# Replace "{z}/{x}/{y}" with "%s"
# If placeholders present, validate they have no additional spaces
pattern = re.compile(r"\{\s*[xyz]+\s*\}")
if bool(pattern.search(url)):
msg = "Invalid TMS URL format. Please check the URL placeholders {z}/{x}/{y}."
log.error(msg)
raise ValueError(msg)

# Remove "{z}/{x}/{y}" placeholders if they are present
url = re.sub(r"/{[xyz]+\}", "", url)
# Append "%s" to the end of the URL to later add the tile path
url = url + r"/%s"

if is_oam:
Expand Down
Loading