hongfaqiu / TIFFImageryProvider

Load GeoTIFF/COG(Cloud optimized GeoTIFF) on Cesium
https://tiff-imagery-provider.opendde.com/?panel=layer
MIT License
52 stars 10 forks source link

TypeError: Cannot read properties of undefined (reading 'hasAlphaChannel') #17

Closed quater23 closed 1 year ago

quater23 commented 1 year ago

https://github.com/hongfaqiu/TIFFImageryProvider/blob/18c4015bfc545debe2bb079a172b239c68324848/packages/TIFFImageryProvider/src/TIFFImageryProvider.ts#L361

When i use this code to load tiff, it is error. code:

const provider = await TIFFImageryProvider.fromUrl(url);
viewer.imageryLayers.addImageryProvider(provider);

error info:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'hasAlphaChannel')
at new TIFFImageryProvider (TIFFImageryProvider.ts:172:36)
at TIFFImageryProvider.<anonymous> (TIFFImageryProvider.ts:362:22)
at Generator.next (<anonymous>)
at tslib.es6.js:121:71
at new Promise (<anonymous>)
at __awaiter (tslib.es6.js:117:12)
at TIFFImageryProvider.fromUrl (TIFFImageryProvider.ts:361:87)

The reason for the error is that i didn't pass in options, so it is undefined , but the TIFFImageryProvider function need its attributes.

static async fromUrl(url: string | File | Blob, options?: TIFFImageryProviderOptions) {
    const provider = new TIFFImageryProvider(options);
    await provider._build(url, options)

    return provider;
  }

so may be you can change the source code like this:

static async fromUrl(url: string | File | Blob, options?: TIFFImageryProviderOptions) {
    if(options === undefined){
     options = {};
   }
    const provider = new TIFFImageryProvider(options);
    await provider._build(url, options)

    return provider;
  }
quater23 commented 1 year ago

version: "tiff-imagery-provider": "^2.6.5",

hongfaqiu commented 1 year ago

ts报错是因为TIFFImageryProvider没有完全扩展ImageryProvider的属性,这样写就没事了:

const provider: any = await TIFFImageryProvider.fromUrl(url);
viewer.imageryLayers.addImageryProvider(provider);
quater23 commented 1 year ago

ok,但我用的是js,一开始按照文档上那样写就报错了,后来改成这样就可以:

const provider = await TIFFImageryProvider.fromUrl(url, {});

也许你可以在文档上标注一下😃

hongfaqiu commented 1 year ago

感谢,已修复