From ba444117bb07cc540d769e8f76e986a1232eb001 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 1 Oct 2021 11:47:27 -0600 Subject: [PATCH] Use nodata values in the GeoTIFF headers for fill value --- src/ol/source/GeoTIFF.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ol/source/GeoTIFF.js b/src/ol/source/GeoTIFF.js index eadf679630..e94045f919 100644 --- a/src/ol/source/GeoTIFF.js +++ b/src/ol/source/GeoTIFF.js @@ -582,6 +582,7 @@ class GeoTIFFSource extends DataTile { const addAlpha = this.addAlpha_; const bandCount = this.bandCount; const samplesPerPixel = this.samplesPerPixel_; + const nodataValues = this.nodataValues_; const sourceInfo = this.sourceInfo_; for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) { const source = sourceInfo[sourceIndex]; @@ -599,12 +600,27 @@ class GeoTIFFSource extends DataTile { return bandNumber - 1; }); } + + /** @type {number|Array} */ + let fillValue; + if (!isNaN(source.nodata)) { + fillValue = source.nodata; + } else { + if (!samples) { + fillValue = nodataValues[sourceIndex]; + } else { + fillValue = samples.map(function (sampleIndex) { + return nodataValues[sourceIndex][sampleIndex]; + }); + } + } + requests[sourceIndex] = image[this.readMethod_]({ window: pixelBounds, width: size[0], height: size[1], samples: samples, - fillValue: source.nodata, + fillValue: fillValue, pool: getWorkerPool(), interleave: false, }); @@ -612,7 +628,6 @@ class GeoTIFFSource extends DataTile { const pixelCount = size[0] * size[1]; const dataLength = pixelCount * bandCount; - const nodataValues = this.nodataValues_; const normalize = this.normalize_; return Promise.all(requests).then(function (sourceSamples) {