diff --git a/examples/cog-math-multisource.js b/examples/cog-math-multisource.js index 1f1d6f3583..05da37fc43 100644 --- a/examples/cog-math-multisource.js +++ b/examples/cog-math-multisource.js @@ -7,14 +7,14 @@ const source = new GeoTIFF({ sources: [ { url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R10m.tif', - bands: [2, 3], + bands: [3, 4], min: 0, nodata: 0, max: 65535, }, { url: 'https://s2downloads.eox.at/demo/Sentinel-2/3857/R60m.tif', - bands: [8], + bands: [9], min: 0, nodata: 0, max: 65535, diff --git a/src/ol/source/GeoTIFF.js b/src/ol/source/GeoTIFF.js index 15c56576c3..e59c7b28a4 100644 --- a/src/ol/source/GeoTIFF.js +++ b/src/ol/source/GeoTIFF.js @@ -20,9 +20,9 @@ import {toSize} from '../size.js'; * the configured min and max. * @property {number} [nodata] Values to discard. When provided, an additional band (alpha) will be added * to the data. - * @property {Array} [bands] Indices of the bands to be read from. If not provided, all bands will - * be read. If, for example, a GeoTIFF has red, green, blue and near-infrared bands and you only need the - * infrared band, configure `bands: [3]`. + * @property {Array} [bands] Band numbers to be read from (where the first band is `1`). If not provided, all bands will + * be read. For example, if a GeoTIFF has blue (1), green (2), red (3), and near-infrared (4) bands, and you only need the + * near-infrared band, configure `bands: [4]`. */ let workerPool; @@ -385,7 +385,7 @@ class GeoTIFFSource extends DataTile { const bands = this.sourceInfo_[sourceIndex].bands; if (bands) { for (let i = 0; i < bands.length; ++i) { - if (!isNaN(values[bands[i]])) { + if (!isNaN(values[bands[i] - 1])) { this.addAlpha_ = true; break outer; } @@ -442,11 +442,17 @@ class GeoTIFFSource extends DataTile { Math.round((y + 1) * (size[1] * resolutionFactor)), ]; const image = this.sourceImagery_[sourceIndex][z]; + let samples; + if (source.bands) { + samples = source.bands.map(function (bandNumber) { + return bandNumber - 1; + }); + } requests[sourceIndex] = image.readRasters({ window: pixelBounds, width: size[0], height: size[1], - samples: source.bands, + samples: samples, fillValue: source.nodata, pool: getWorkerPool(), }); @@ -491,7 +497,7 @@ class GeoTIFFSource extends DataTile { if (nodata === undefined) { let bandIndex; if (source.bands) { - bandIndex = source.bands[sampleIndex]; + bandIndex = source.bands[sampleIndex] - 1; } else { bandIndex = sampleIndex; }