Skip to content

Commit

Permalink
Add support for d2s (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Aug 17, 2024
1 parent 4af36e2 commit 96ccb2d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14117,3 +14117,32 @@ def ee_tile_url(
except Exception as e:
print(e)
return None


def d2s_tile(
url: str, titiler_endpoint: str = "https://tt.d2s.org", **kwargs: Any
) -> str:
"""Generate a D2S tile URL with optional API key.
Args:
url (str): The base URL for the tile.
titiler_endpoint (str, optional): The endpoint for the titiler service.
Defaults to "https://tt.d2s.org".
**kwargs (Any): Additional keyword arguments to pass to the cog_stats function.
Returns:
str: The modified URL with the API key if required, otherwise the original URL.
Raises:
ValueError: If the API key is required but not set in the environment variables.
"""

stats = cog_stats(url, titiler_endpoint=titiler_endpoint, **kwargs)
if "detail" in stats:
api_key = get_api_key("D2S_API_KEY")
if api_key is None:
raise ValueError("Please set the D2S_API_KEY environment variable.")
else:
return f"{url}?API_KEY={api_key}"
else:
return url
2 changes: 1 addition & 1 deletion leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def add_cog_layer(
visible: bool = True,
bands: Optional[List[int]] = None,
nodata: Optional[Union[int, float]] = 0,
titiler_endpoint: str = "https://titiler.xyz",
titiler_endpoint: str = None,
fit_bounds: bool = True,
before_id: Optional[str] = None,
**kwargs: Any,
Expand Down

0 comments on commit 96ccb2d

Please sign in to comment.