Fix heatmap crash on small datasets by clamping percentile indices

Math.round(values.length * 0.95) produces an out-of-bounds index when
the dataset has fewer than ~20 features (e.g. after tight travel time
filtering). values[outOfBounds] returns undefined, cascading to NaN
color stops which crash Mapbox's expression evaluator. Clamp both
min and max indices to values.length - 1.
This commit is contained in:
Viktor Barzin 2026-02-08 17:46:33 +00:00
parent 07d4fa5f84
commit 1f4a3f858c
No known key found for this signature in database
GPG key ID: 0EB088298288D958

View file

@ -103,8 +103,8 @@ export function Map(props: MapProps) {
.sort(function (a: number, b: number) { return a - b; }); .sort(function (a: number, b: number) { return a - b; });
if (values.length > 0) { if (values.length > 0) {
const minIndex = Math.round(values.length * PERCENTILE_CONFIG.MIN_BOUND); const minIndex = Math.min(Math.round(values.length * PERCENTILE_CONFIG.MIN_BOUND), values.length - 1);
const maxIndex = Math.round(values.length * PERCENTILE_CONFIG.MAX_BOUND); const maxIndex = Math.min(Math.round(values.length * PERCENTILE_CONFIG.MAX_BOUND), values.length - 1);
const min = values[minIndex]; const min = values[minIndex];
// Ensure max > min so color stops are strictly monotonic // Ensure max > min so color stops are strictly monotonic
const max = Math.max(values[maxIndex], min + 1); const max = Math.max(values[maxIndex], min + 1);