From 4ad19a6d7f3e98605e7e3892a5dd32a5978ee4d7 Mon Sep 17 00:00:00 2001 From: Petr Sloup Date: Sun, 3 Dec 2023 11:26:27 +0100 Subject: [PATCH] Handle loading of empty raster tiles (204 No Content) (#3428) * Handle empty raster tiles * Improve `arrayBufferToImageBitmap` to handle empty buffers * Add changelog entry --- CHANGELOG.md | 1 + src/util/util.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf3c82d0b..3e6801e83a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,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 diff --git a/src/util/util.ts b/src/util/util.ts index 6f597d4399..c9fd1bc6e8 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -461,6 +461,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);