Skip to content

Commit

Permalink
fix: multi band tiff single band rendering #20
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed Sep 4, 2023
1 parent 845648b commit eb4a653
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/TIFFImageryProvider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Load GeoTIFF/COG(Cloud optimized GeoTIFF) on Cesium
- Web Workers speed up.
- WebGL accelerated rendering.
- Band calculation.
- Support any projected TIFF (experimental).
- **[experimental]** Support any projected TIFF .

## Install

Expand Down Expand Up @@ -130,6 +130,10 @@ interface TIFFImageryProviderOptions {
enablePickFeatures?: boolean;
hasAlphaChannel?: boolean;
renderOptions?: TIFFImageryProviderRenderOptions;
/**
* If TIFF's projection is not EPSG:4326 or EPSG:3857, you can pass the ``projFunc`` to handle the projection
* @experimental
*/
projFunc?: (code: number) => {
/** projection function, convert [lon, lat] position to [x, y] */
project: ((pos: number[]) => number[]);
Expand Down
4 changes: 4 additions & 0 deletions packages/TIFFImageryProvider/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ interface TIFFImageryProviderOptions {
enablePickFeatures?: boolean;
hasAlphaChannel?: boolean;
renderOptions?: TIFFImageryProviderRenderOptions;
/**
* 如果 TIFF 的投影不是 EPSG:4326,你可以通过 ``projFunc`` 来处理投影
* @experimental
*/
projFunc?: (code: number) => {
/** 投影函数,将 [lon, lat] 位置转换为 [x, y] */
project: ((pos: number[]) => number[]);
Expand Down
10 changes: 6 additions & 4 deletions packages/TIFFImageryProvider/src/TIFFImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export interface TIFFImageryProviderOptions {
enablePickFeatures?: boolean;
hasAlphaChannel?: boolean;
renderOptions?: TIFFImageryProviderRenderOptions;
/**
* If TIFF's projection is not EPSG:4326 or EPSG:3857, you can pass the ``projFunc`` to handle the projection
* @experimental
*/
projFunc?: (code: number) => {
/** projection function, convert [lon, lat] position to [x, y] */
project: ((pos: number[]) => number[]);
Expand Down Expand Up @@ -175,7 +179,6 @@ export class TIFFImageryProvider {
data: ImageBitmap | HTMLCanvasElement | HTMLImageElement;
}> = {};
private _generateImageworkerFarm: WorkerFarm | null;
private _reprojectionworkerFarm: WorkerFarm;
private _cacheTime: number;
private _isTiled: boolean;
private _proj?: {
Expand Down Expand Up @@ -278,7 +281,7 @@ export class TIFFImageryProvider {
throw error;
}
if (!this.renderOptions.single && !this.renderOptions.multi && !this.renderOptions.convertToRGB) {
if (samples > 1) {
if (samples > 2) {
this.renderOptions = {
convertToRGB: true,
...this.renderOptions
Expand All @@ -297,7 +300,7 @@ export class TIFFImageryProvider {
}

const { single, multi, convertToRGB } = this.renderOptions;
this.readSamples = multi ? [multi.r.band - 1, multi.g.band - 1, multi.b.band - 1] : convertToRGB ? [0, 1, 2] : [0]
this.readSamples = multi ? [multi.r.band - 1, multi.g.band - 1, multi.b.band - 1] : convertToRGB ? [0, 1, 2] : Array.from({ length: samples }, (_, index) => index);
if (single?.expression) {
this.readSamples = findAndSortBandNumbers(single.expression);
}
Expand Down Expand Up @@ -470,7 +473,6 @@ export class TIFFImageryProvider {
]
}


const options = {
window,
pool: getWorkerPool(),
Expand Down

0 comments on commit eb4a653

Please sign in to comment.