Skip to content

Commit

Permalink
Merge pull request #39 from carbonplan/katamartin/remove-kwargs-depen…
Browse files Browse the repository at this point in the history
…dency

Inspect datasets array instead of using kwargs
  • Loading branch information
katamartin authored Dec 11, 2021
2 parents dfcc0fa + 686012f commit a3cab7c
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,31 @@ export const getTilesOfRegion = (region, level) => {
}

export const getPyramidMetadata = (metadata) => {
const kwargs = metadata.metadata['.zattrs'].multiscales[0].metadata.kwargs
const maxZoom = kwargs.levels - 1
const levels = Array(maxZoom + 1)
.fill()
.map((_, i) => i)
const tileSize = kwargs.pixels_per_tile
const multiscales = metadata.metadata['.zattrs'].multiscales

if (!multiscales) {
throw new Error(
'Missing `multiscales` value in .zattrs. Please check your pyramid generation code.'
)
}

const datasets = multiscales[0].datasets

if (!datasets || datasets.length === 0) {
throw new Error(
'No datasets provided in `multiscales` metadata. Please check your pyramid generation code.'
)
}

const levels = datasets.map((dataset) => Number(dataset.path))
const maxZoom = Math.max(...levels)
const tileSize = datasets[0].pixels_per_tile

if (!tileSize) {
throw new Error(
'Missing required `pixels_per_tile` value in `multiscales` metadata. Please check your pyramid generation code.'
)
}
return { levels, maxZoom, tileSize }
}

Expand Down

1 comment on commit a3cab7c

@vercel
Copy link

@vercel vercel bot commented on a3cab7c Dec 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.