Skip to content

Commit 8db4036

Browse files
dcojgithub-actions[bot]
authored andcommitted
Fix raster-array out of bounds assertion error for non-mecator projections
GitOrigin-RevId: 06f8e3a151876b4ca87c2d9dd52e2c8796e8121b
1 parent 72a570e commit 8db4036

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

debug/raster-array.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
import {getAccessToken} from './access_token_generated.js';
5151
import {Pane} from 'https://cdn.jsdelivr.net/npm/tweakpane@4.0.3/dist/tweakpane.min.js';
5252

53+
const urlParams = new URLSearchParams(window.location.search);
54+
5355
const PARAMS = {
5456
bandIndex: 0,
55-
projection: 'mercator',
57+
projection: urlParams.get('projection') || 'globe',
5658
colorScale: 'Spectral',
5759
};
5860

@@ -90,6 +92,7 @@
9092
center: [135.0053045734985, 36.00653610439714],
9193
zoom: 1,
9294
hash: true,
95+
projection: PARAMS.projection,
9396
});
9497

9598
map.addControl(new mapboxgl.NavigationControl());
@@ -198,6 +201,9 @@
198201
}
199202
}).on('change', (e) => {
200203
map.setProjection(e.value);
204+
const params = new URLSearchParams(window.location.search);
205+
params.set('projection', e.value);
206+
window.history.replaceState(null, '', `?${params.toString()}${window.location.hash}`);
201207
});
202208
pane.addBinding(PARAMS, 'colorScale', {label: 'Color scale', options: colorScaleOptions})
203209
.on('change', (e) => map.setPaintProperty('precipitations', 'raster-color', getRasterColor(e.value)));

src/source/raster_array_tile_source.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ class RasterArrayTileSource extends RasterTileSource<'raster-array'> {
423423
const px = point.x - wrap;
424424
const x = Math.floor(px * tiles);
425425
const y = Math.floor(point.y * tiles);
426+
// Guard for non-Mercator projections that show latitudes beyond the Mercator limit
427+
if (x < 0 || x >= tiles || y < 0 || y >= tiles) return null;
426428
const sourceCache = this.map.style.getSourceCache(this.id);
427429
const tileID = new OverscaledTileID(z, wrap, z, x, y);
428430
return sourceCache.findLoadedParent(tileID, this.minzoom) as RasterArrayTile | null | undefined;

0 commit comments

Comments
 (0)