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:
parent
07d4fa5f84
commit
1f4a3f858c
1 changed files with 2 additions and 2 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue