diff --git a/leafmap/common.py b/leafmap/common.py index 4cc4345891..fccd852d12 100644 --- a/leafmap/common.py +++ b/leafmap/common.py @@ -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 diff --git a/leafmap/maplibregl.py b/leafmap/maplibregl.py index 62464857a4..5f4305d2af 100644 --- a/leafmap/maplibregl.py +++ b/leafmap/maplibregl.py @@ -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,