Skip to content

Commit

Permalink
fix remaining flow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Feb 1, 2022
1 parent 2ad0acb commit 619ac4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/render/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Texture {
if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData || (ImageBitmap && image instanceof ImageBitmap)) {
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, gl.UNSIGNED_BYTE, image);
} else {
// $FlowFixMe prop-missing - Flow can't refine image type here
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, gl.UNSIGNED_BYTE, image.data);
}

Expand All @@ -75,6 +76,7 @@ class Texture {
if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData || (ImageBitmap && image instanceof ImageBitmap)) {
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, gl.RGBA, gl.UNSIGNED_BYTE, image);
} else {
// $FlowFixMe prop-missing - Flow can't refine image type here
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, image.data);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1935,8 +1935,9 @@ class Map extends Camera {
'Invalid arguments to map.addImage(). The second argument must be an `HTMLImageElement`, `ImageData`, `ImageBitmap`, ' +
'or object with `width`, `height`, and `data` properties with the same format as `ImageData`')));
} else {
const {width, height, data} = image;
const {width, height} = image;
const userImage = ((image: any): StyleImageInterface);
const data = userImage.data;

this.style.addImage(id, {
data: new RGBAImage({width, height}, new Uint8Array(data)),
Expand Down Expand Up @@ -1982,7 +1983,9 @@ class Map extends Camera {
'The map has no image with that id. If you are adding a new image use `map.addImage(...)` instead.')));
}
const imageData = (image instanceof window.HTMLImageElement || (window.ImageBitmap && image instanceof window.ImageBitmap)) ? browser.getImageData(image) : image;
const {width, height, data} = imageData;
const {width, height} = imageData;
// Flow can't refine the type enough to exclude ImageBitmap
const data = ((imageData: any).data: Uint8Array | Uint8ClampedArray);

if (width === undefined || height === undefined) {
return this.fire(new ErrorEvent(new Error(
Expand Down

0 comments on commit 619ac4c

Please sign in to comment.