From b92bf5e338749b7fea71fe06e667163bee1b84bd Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Thu, 30 Nov 2023 15:04:44 +0100 Subject: [PATCH 1/3] Handle empty raster tiles --- src/util/image_request.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/image_request.ts b/src/util/image_request.ts index 1c2041495e..85f83cdcca 100644 --- a/src/util/image_request.ts +++ b/src/util/image_request.ts @@ -133,7 +133,7 @@ export namespace ImageRequest { const arrayBufferToCanvasImageSource = (data: ArrayBuffer): Promise => { const imageBitmapSupported = typeof createImageBitmap === 'function'; - if (imageBitmapSupported) { + if (imageBitmapSupported && data.byteLength) { return arrayBufferToImageBitmap(data); } else { return arrayBufferToImage(data); From 90cef6a5aa8d5332e7fbf480058d6505ee54713e Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Fri, 1 Dec 2023 13:18:46 +0100 Subject: [PATCH 2/3] Improve `arrayBufferToImageBitmap` to handle empty buffers --- src/util/image_request.ts | 2 +- src/util/util.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/image_request.ts b/src/util/image_request.ts index 85f83cdcca..1c2041495e 100644 --- a/src/util/image_request.ts +++ b/src/util/image_request.ts @@ -133,7 +133,7 @@ export namespace ImageRequest { const arrayBufferToCanvasImageSource = (data: ArrayBuffer): Promise => { const imageBitmapSupported = typeof createImageBitmap === 'function'; - if (imageBitmapSupported && data.byteLength) { + if (imageBitmapSupported) { return arrayBufferToImageBitmap(data); } else { return arrayBufferToImage(data); diff --git a/src/util/util.ts b/src/util/util.ts index 0c182a1db9..8d0ecb32e8 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -457,6 +457,9 @@ export function isImageBitmap(image: any): image is ImageBitmap { * @returns - A promise resolved when the conversion is finished */ export const arrayBufferToImageBitmap = async (data: ArrayBuffer): Promise => { + if (data.byteLength === 0) { + return createImageBitmap(new ImageData(1, 1)); + } const blob: Blob = new Blob([new Uint8Array(data)], {type: 'image/png'}); try { return createImageBitmap(blob); From e5375f59ee2f645d58a5c8831127b4ce808f48c6 Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Fri, 1 Dec 2023 16:22:00 +0100 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c552929906..e4af4ab080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### 🐞 Bug fixes - Fix zooming outside the central globe when terrain 3D is enabled ([#3425](https://github.com/maplibre/maplibre-gl-js/pull/3425)) +- Handle loading of empty raster tiles (204 No Content) ([#3428](https://github.com/maplibre/maplibre-gl-js/pull/3428)) - _...Add new stuff here..._ ## 4.0.0-pre.1