openlayers: Large image does not load in Static Image Layer

I made several tests on different PCs using same extra large PNG file (7021px x 4967px) A0. On my own PC it works 100% (Windows 64bit - 32Gb Ram), but on another PC (Windows 32bit - 4Gb Ram) it does not load and Openlayers gives an error on the decode promise when trying to decode the image (See below). When I resize the image to 5000px or less, it works.

NOTICE THE LINE: error = DOMException: The source image cannot be decoded

function listenImage (image, loadHandler, errorHandler) {
	var img =
      /** @type {HTMLImageElement} */
      image;

	if (img.src && IMAGE_DECODE) {
		var promise = img.decode();
		var listening_1 = true;

		var unlisten = function () {
			listening_1 = false;
		};

		promise.then(function () {
			if (listening_1) {
				loadHandler();
			}
		}).catch(function (error) {   // **error = DOMException: The source image cannot be decoded**  
			if (listening_1) {
				// FIXME: Unconditionally call errorHandler() when this bug is fixed upstream:
				//        https://bugs.webkit.org/show_bug.cgi?id=198527
				if (error.name === 'EncodingError' && error.message === 'Invalid image type.') {
					loadHandler();
				} else {
					errorHandler();
				}
			}
		});
		return unlisten;
	}

	var listenerKeys = [listenOnce(img, EventType.LOAD, loadHandler), listenOnce(img, EventType.ERROR, errorHandler)];
	return function unlisten () {
		listenerKeys.forEach(unlistenByKey);
	};
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

@rooby That comment is only relevant for svg images. There are several reasons why large images could fail. The first thing to check is whether the generated url can be downloaded stand-alone without error (e.g. with curl, or directly by pasting it into the browser’s address bar. Another problem could be missing CORS headers, but that would also affect small images. And when the download finishes correctly, there is still a chance that the canvas needed to render the image gets bigger than the size supported by the browser and device.

The last mentioned problem is related to #9578. At least on devices with a high device pixel ratio, it could improve the situation when fixed.