Skip to content

Commit 9a3059d

Browse files
authored
Merge pull request #3650 from EPajares/main
Fixed nan values issue for rasters
2 parents 925c63f + 736c326 commit 9a3059d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

apps/web/lib/utils/map/cog-styling.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ function generateColorRangeColorFunction(props: RasterStyleColorRangeProperties)
9797
return (pixel, color, metadata) => {
9898
let value = pixel[band];
9999

100-
// Handle no-data
101-
if (value === null || value === undefined || value === metadata.noData) {
100+
// Handle no-data (including NaN which doesn't equal itself in JS)
101+
if (value === null || value === undefined || value === metadata.noData || Number.isNaN(value)) {
102102
color.set(noDataRgba as unknown as ArrayLike<number>);
103103
return;
104104
}
@@ -183,8 +183,8 @@ function generateCategoriesColorFunction(props: RasterStyleCategoriesProperties)
183183
return (pixel, color, metadata) => {
184184
let value = pixel[band];
185185

186-
// Handle no-data
187-
if (value === null || value === undefined || value === metadata.noData) {
186+
// Handle no-data (including NaN which doesn't equal itself in JS)
187+
if (value === null || value === undefined || value === metadata.noData || Number.isNaN(value)) {
188188
color.set(noDataRgba as unknown as ArrayLike<number>);
189189
return;
190190
}
@@ -225,8 +225,13 @@ function generateHillshadeColorFunction(props: RasterStyleHillshadeProperties):
225225
return (pixel, color, metadata) => {
226226
let elevation = pixel[band];
227227

228-
// Handle no-data
229-
if (elevation === null || elevation === undefined || elevation === metadata.noData) {
228+
// Handle no-data (including NaN which doesn't equal itself in JS)
229+
if (
230+
elevation === null ||
231+
elevation === undefined ||
232+
elevation === metadata.noData ||
233+
Number.isNaN(elevation)
234+
) {
230235
color.set([0, 0, 0, 0]);
231236
return;
232237
}

0 commit comments

Comments
 (0)