From 6868c9f1ce9e449bfdcd90b05f4dc23e4ba8d050 Mon Sep 17 00:00:00 2001 From: katamartin Date: Tue, 26 Mar 2024 10:44:14 -0400 Subject: [PATCH] Avoid errors before metadata initialized --- src/tiles.js | 9 +++++++++ src/utils.js | 1 + 2 files changed, 10 insertions(+) diff --git a/src/tiles.js b/src/tiles.js index f0480bf..45ea158 100644 --- a/src/tiles.js +++ b/src/tiles.js @@ -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 } @@ -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, diff --git a/src/utils.js b/src/utils.js index 64e8191..398c9df 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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])