Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
quater23 opened this issue Jul 3, 2023 · 4 comments
Closed

Comments

@quater23
Copy link

quater23 commented Jul 3, 2023

static async fromUrl(url: string | File | Blob, options?: TIFFImageryProviderOptions) {

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
Copy link
Author

quater23 commented Jul 3, 2023

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

@hongfaqiu
Copy link
Owner

hongfaqiu commented Jul 3, 2023

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

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

@quater23
Copy link
Author

quater23 commented Jul 3, 2023

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

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

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

@hongfaqiu
Copy link
Owner

感谢,已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants