Skip to content

Commit

Permalink
Avoid errors before metadata initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
katamartin committed Mar 26, 2024
1 parent e8af016 commit 6868c9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export const createTiles = (regl, opts) => {
this.projectionIndex = projection
? ['mercator', 'equirectangular'].indexOf(projection)
: ['EPSG:3857', 'EPSG:4326'].indexOf(crs)
this.projection = ['mercator', 'equirectangular'][
this.projectionIndex
]

if (mode === 'grid' || mode === 'dotgrid') {
this.count = position.length
}
Expand Down Expand Up @@ -295,6 +299,11 @@ export const createTiles = (regl, opts) => {
}

this.updateCamera = ({ center, zoom }) => {
// Return early if projection not yet initialized
if (!this.projection) {
return
}

const level = zoomToLevel(zoom, this.maxZoom)
const tile = pointToTile(
center.lng,
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const pointToTile = (lon, lat, z, projection, order) => {
y = Math.max(Math.min(y, z2), 0)
tile = [x, y, z]
default:
return
break
}
tile[0] = Math.floor(tile[0])
Expand Down

0 comments on commit 6868c9f

Please sign in to comment.