Skip to content

Commit

Permalink
Support metadata from local pmtiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Jul 19, 2024
1 parent 851b870 commit b25d819
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions maplibre/pmtiles_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ def get_pmtiles_header(path: str) -> dict:

def get_pmtiles_metadata(path: str) -> tuple:
header = get_pmtiles_header(path)
response = range_request(path, header["metadata_offset"], header["metadata_length"])
get_bytes = MemorySource(response.content)
metadata = get_bytes(0, header["metadata_length"])
if path.startswith("http"):
response = range_request(
path, header["metadata_offset"], header["metadata_length"]
)
get_bytes = MemorySource(response.content)
metadata = get_bytes(0, header["metadata_length"])
else:
with open(path, "rb") as f:
get_bytes = MmapSource(f)
metadata = get_bytes(header["metadata_offset"], header["metadata_length"])

if header["internal_compression"] == Compression.GZIP:
metadata = gzip.decompress(metadata)

Expand Down Expand Up @@ -187,6 +195,7 @@ def to_basemap_style(self, layer_styles: list) -> dict:
},
)
)

return construct_basemap_style(
sources={source_id: self.to_source()}, layers=layers
)

0 comments on commit b25d819

Please sign in to comment.