Skip to content

Commit

Permalink
Add read_geojson function (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Oct 26, 2024
1 parent 3977fcd commit 751862b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14853,3 +14853,18 @@ def find_max_value_coords(
x, y = transformer.transform(x, y)

return x, y, max_value


def read_geojson(data: str, **kwargs: Any) -> Dict[str, Any]:
"""
Fetches and parses a GeoJSON file from a given URL.
Args:
data (str): The URL of the GeoJSON file.
**kwargs (Any): Additional keyword arguments to pass to the requests.get() method.
Returns:
Dict[str, Any]: The parsed GeoJSON data.
"""

return requests.get(data, **kwargs).json()
8 changes: 4 additions & 4 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3318,7 +3318,7 @@ def construct_maptiler_style(style: str, api_key: Optional[str] = None) -> str:
This function generates a URL for accessing a specific MapTiler map style. If an API key is not provided,
it attempts to retrieve one using a predefined method. If the request to MapTiler fails, it defaults to
a "dark-matter" style.
a "liberty" style.
Args:
style (str): The name of the MapTiler style to be accessed. It can be one of the following:
Expand All @@ -3328,7 +3328,7 @@ def construct_maptiler_style(style: str, api_key: Optional[str] = None) -> str:
attempts to retrieve the API key using a predefined method. Defaults to None.
Returns:
str: The URL for the requested MapTiler style. If the request fails, returns a URL for the "dark-matter" style.
str: The URL for the requested MapTiler style. If the request fails, returns a URL for the "liberty" style.
Raises:
requests.exceptions.RequestException: If the request to the MapTiler API fails.
Expand All @@ -3342,9 +3342,9 @@ def construct_maptiler_style(style: str, api_key: Optional[str] = None) -> str:
response = requests.get(url)
if response.status_code != 200:
print(
"Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style."
"Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style."
)
url = "dark-matter"
url = "https://tiles.openfreemap.org/styles/liberty"

return url

Expand Down

0 comments on commit 751862b

Please sign in to comment.