Merge pull request #13290 from constantinius/geotiff-source-options
Allowing to pass additional options to the geotiff.js source
This commit is contained in:
@@ -207,14 +207,15 @@ function getImagesForTIFF(tiff) {
|
||||
|
||||
/**
|
||||
* @param {SourceInfo} source The GeoTIFF source.
|
||||
* @param {object} options Options for the GeoTIFF source.
|
||||
* @return {Promise<Array<GeoTIFFImage>>} Resolves to a list of images.
|
||||
*/
|
||||
function getImagesForSource(source) {
|
||||
function getImagesForSource(source, options) {
|
||||
let request;
|
||||
if (source.overviews) {
|
||||
request = tiffFromUrls(source.url, source.overviews);
|
||||
request = tiffFromUrls(source.url, source.overviews, options);
|
||||
} else {
|
||||
request = tiffFromUrl(source.url);
|
||||
request = tiffFromUrl(source.url, options);
|
||||
}
|
||||
return request.then(getImagesForTIFF);
|
||||
}
|
||||
@@ -298,6 +299,20 @@ function getMaxForDataType(array) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} GeoTIFFSourceOptions
|
||||
* @property {boolean} [forceXHR=false] Whether to force the usage of the browsers XMLHttpRequest API.
|
||||
* @property {Object<string, string>} [headers] additional key-value pairs of headers to be passed with each request. Key is the header name, value the header value.
|
||||
* @property {string} [credentials] How credentials shall be handled. See
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/fetch for reference and possible values
|
||||
* @property {number} [maxRanges] The maximum amount of ranges to request in a single multi-range request.
|
||||
* By default only a single range is used.
|
||||
* @property {boolean} [allowFullFile=false] Whether or not a full file is accepted when only a portion is
|
||||
* requested. Only use this when you know the source image to be small enough to fit in memory.
|
||||
* @property {number} [blockSize=65536] The block size to use.
|
||||
* @property {number} [cacheSize=100] The number of blocks that shall be held in a LRU cache.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Array<SourceInfo>} sources List of information about GeoTIFF sources.
|
||||
@@ -308,6 +323,7 @@ function getMaxForDataType(array) {
|
||||
* sources, one with 3 bands and {@link import("./GeoTIFF.js").SourceInfo nodata} configured, and
|
||||
* another with 1 band, the resulting data tiles will have 5 bands: 3 from the first source, 1 alpha
|
||||
* band from the first source, and 1 band from the second source.
|
||||
* @property {GeoTIFFSourceOptions} [sourceOptions] Additional options to be passed to [geotiff.js](https://geotiffjs.github.io/geotiff.js/module-geotiff.html)'s `fromUrl` or `fromUrls` methods.
|
||||
* @property {boolean} [convertToRGB = false] By default, bands from the sources are read as-is. When
|
||||
* reading GeoTIFFs with the purpose of displaying them as RGB images, setting this to `true` will
|
||||
* convert other color spaces (YCbCr, CMYK) to RGB.
|
||||
@@ -351,6 +367,12 @@ class GeoTIFFSource extends DataTile {
|
||||
|
||||
const numSources = this.sourceInfo_.length;
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
* @private
|
||||
*/
|
||||
this.sourceOptions_ = options.sourceOptions;
|
||||
|
||||
/**
|
||||
* @type {Array<Array<GeoTIFFImage>>}
|
||||
* @private
|
||||
@@ -409,7 +431,10 @@ class GeoTIFFSource extends DataTile {
|
||||
const self = this;
|
||||
const requests = new Array(numSources);
|
||||
for (let i = 0; i < numSources; ++i) {
|
||||
requests[i] = getImagesForSource(this.sourceInfo_[i]);
|
||||
requests[i] = getImagesForSource(
|
||||
this.sourceInfo_[i],
|
||||
this.sourceOptions_
|
||||
);
|
||||
}
|
||||
Promise.all(requests)
|
||||
.then(function (sources) {
|
||||
|
||||
Reference in New Issue
Block a user