Error when updating to CesiumJS 1.92

Hi everyone,

I have tried to update to CesiumJS 1.92 but i face an issue. When i launch my apps after upgrading, I now have this message and the earth is not rendered !

An error occurred while rendering.  Rendering has stopped.
TypeError: o.then is not a function
r@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2630581
ImageryLayer.prototype._requestImagery@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2630785
Imagery.prototype.processStateMachine@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2623573
TileImagery.prototype.processStateMachine@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2624213
GlobeSurfaceTile.prototype.processImagery@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2615517
GlobeSurfaceTile.processStateMachine@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2614858
GlobeSurfaceTileProvider.prototype.loadTile@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2664228
processSinglePriorityLoadQueue@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2721397
processTileLoadQueue@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2720987
QuadtreePrimitive.prototype.endFrame@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2711217
Globe.prototype.endFrame@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:2733336
render@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:3106580
tryAndCatchError@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:3106687
Scene.prototype.render@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:3108572
CesiumWidget.prototype.render@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:113237
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98897
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915
FrameRequestCallback*requestAnimationFramePolyFill@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:48:256453
n@http://localhost:9090/node_modules/cesium/Build/Cesium/Cesium.js:90:98915

Before upgrading, i have read this thread containing the guide to follow in order to upgrade to 1.92 and change what requested to change.
(The only part of my code using when is in webglglobedatasource but i change it according to the sandcastle example).

I have check many times my code according to the guide, but all the part have been change as requested. I do not understand the error, do you have an idea ?

Thanks in advance, best regards.
Emmanuel.

Hi Emmanuel,

Would you be able to provide the relevant source code from webglglobedatasource, or a sandcastle example that reproduces the error? Also, it looks like you’re using minified cesium, so the error stack here obscures some information. Would it be possible to use uncombined cesium for debugging purposes?

Thanks,
Gabby

1 Like

Hi Gabby,

Even if i remove completely the webglglobedatasource from my code, i face the same issue.
I am not able to provide a sandcastle example because we use Cesium in a large application for space simulation purpose.

With the unminified version of CesiumJS, this is the error message:

An error occurred while rendering.  Rendering has stopped.
TypeError: imagePromise.then is not a function
TypeError: imagePromise.then is not a function
    at doRequest (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:295376:10)
    at ImageryLayer._requestImagery (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:295384:5)
    at Imagery.processStateMachine (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:294250:25)
    at TileImagery.processStateMachine (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:294326:20)
    at GlobeSurfaceTile.processImagery (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:293505:47)
    at Function.GlobeSurfaceTile.processStateMachine (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:293438:46)
    at GlobeSurfaceTileProvider.loadTile (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:298735:26)
    at processSinglePriorityLoadQueue (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:303752:20)
    at processTileLoadQueue (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:303703:26)
    at QuadtreePrimitive.endFrame (http://localhost:9090/node_modules/cesium/Build/CesiumUnminified/Cesium.js:302824:5)
CesiumWidget.showErrorPanel @ CesiumWidget.js:691

In my application, i have created a viewer object in a viewer.js file. This JS object contains the Cesium Viewer. I just call const viewer = new Viewer(cesiumIonToken, cartography, cartographyDefault); in my index.js file. You can find the code of the viewer.js file below:

"use strict";

/** viewer.js
 * This file contains the Viewer class implementing the 3D viewer based on CesiumJS.
 * It is organised as follow:
 * 1. Import: import necessary objects
 * 2. Viewer: the viewer object
 */

//////////////////////////////////////////////////////////////////////////
// 1. Import
//////////////////////////////////////////////////////////////////////////
import EntityManager from "./entitymanager.js";

//////////////////////////////////////////////////////////////////////////
// 2. Viewer
//////////////////////////////////////////////////////////////////////////
export default class Viewer {
	// Viewer constructor
	constructor(accessToken, cartography, cartographyDefault) {
		// Cesium ION access key
		Cesium.Ion.defaultAccessToken = accessToken;

		// Default parameters
		if (cartography === undefined) {
			cartography = new Map();
		}

		if (cartographyDefault === undefined || cartographyDefault === "") {
			cartographyDefault = "Earth";
		}

		// Home coordinates
		const home = new Cesium.Cartesian3.fromDegrees(2.2356507778167725, 48.715614318847656, 25000000);
		const homeCameraView = {
			destination: home,
		};

		// Creating Cesium viewer
		this.viewer = new Cesium.Viewer("cesium", {
			terrainProvider: new Cesium.EllipsoidTerrainProvider(),
			shouldAnimate: false,
			selectionIndicator: true,
			animation: false,
			timeline: false,
			fullscreenButton: false,
			sceneModePicker: false,
			geocoder: false,
			homeButton: false,
			baseLayerPicker: false,
			imageryProvider: false,
			requestRenderMode: false,
			navigationHelpButton: false,
			targetFrameRate: 30,
			maximumRenderTimeChange: 10.0,
			contextOptions: {
				requestWebgl2: true,
			},
			msaaSamples: 1
		});

		console.log("[Viewer] Cesium Viewer created\n");

		this.viewer.websocketId = "no gateway";
		this.viewer.home = home;

		const scene = this.viewer.scene;
		const clock = this.viewer.clock;
		const camera = this.viewer.camera;
		const globe = scene.globe;
		const ellipsoid = globe.ellipsoid;

		this.volume = new EntityManager(this.viewer);

		// Creating Cesium imagery
		this.viewer.cartography = new Map(cartography);
		this.viewer.cartography.set("Earth", ["default", ""]);
		this.viewer.cartography.set("Day and Night", ["dynamic", ""]);
		this.cartography(cartographyDefault);
		console.log("[Viewer] Cesium Imagery created (default: " + cartographyDefault + ") \n");

		// Configuring Cesium HTML widgets
		new Cesium.NavigationHelpButton({ container: "navigationhelppicker" });
		new Cesium.FullscreenButton("fullscreen");

		const clockViewModel = new Cesium.ClockViewModel(clock);
		const animationViewModel = new Cesium.AnimationViewModel(clockViewModel);

		const animationDiv = document.getElementById("animation");
		if (animationDiv !== null) {
			new Cesium.Animation("animation", animationViewModel);
		}

		function onTimelineScrubfunction(e) {
			const clock = e.clock;
			clock.currentTime = e.timeJulian;
			clock.shouldAnimate = false;
		}

		const timelineDiv = document.getElementById("timeline");
		if (timelineDiv !== null) {
			this.timeline = new Cesium.Timeline("timeline", clock);
			this.timeline.addEventListener("settime", onTimelineScrubfunction, false);
			this.updateTimeline(clock.currentTime);
		}

		function tick() {
			clock.tick();
			Cesium.requestAnimationFrame(tick);
		}
		Cesium.requestAnimationFrame(tick);
		console.log("[Viewer] Cesium HTML widgets created\n");

		// Configuring the Cesium scene
		globe.enableLighting = true;
		globe.dynamicAtmosphereLighting = true;
		globe.dynamicAtmosphereLightingFromSun = true;
		globe.showGroundAtmosphere = true;
		globe.depthTestAgainstTerrain = true;

		globe.lambertDiffuseMultiplier = 10.0;
		globe.lightingFadeOutDistance = 10000000;
		globe.lightingFadeInDistance = 20000000;
		globe.nightFadeOutDistance = 1000000;
		globe.nightFadeInDistance = 10000000;

		// Set the initial view
		scene.camera.frustum.far = 1e12;
		scene.camera.setView(homeCameraView);
		scene.debugShowFramesPerSecond = false;
		scene.skyAtmosphere = new Cesium.SkyAtmosphere();
		scene.skyAtmosphere.show = true;
		scene.skyBox.destroy();
		scene.skyBox = new Cesium.SkyBox({
			sources: {
				positiveX: "../assets/textures/skybox_px.jpg",
				negativeX: "../assets/textures/skybox_nx.jpg",
				positiveY: "../assets/textures/skybox_py.jpg",
				negativeY: "../assets/textures/skybox_ny.jpg",
				positiveZ: "../assets/textures/skybox_pz.jpg",
				negativeZ: "../assets/textures/skybox_nz.jpg"
			}
		});
		scene.skyBox.show = true;
		scene.moon.show = false;
		scene.moon.textureUrl = "../assets/textures/moon.jpg";
		scene.referenceFrame = "fixed";
		scene.cartoPositionBool = false;
		scene.cartoElement = undefined;
		console.log("[Viewer] Cesium scene initialized\n");

		// Configuring Cesium EventListener
		// Canvas
		scene.canvas.addEventListener("mousemove", function (e) {
			if (scene.cartoPositionBool) {
				const cartesian = camera.pickEllipsoid(new Cesium.Cartesian3(e.clientX, e.clientY), ellipsoid);
				if (cartesian) {
					const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
					const longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(4);
					const latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(4);
					if (scene.cartoElement !== undefined) {
						scene.cartoElement.innerHTML = "Longitude: " + ("   " + longitudeString).slice(-7) + "\u00B0" + " | Latitude: " + ("   " + latitudeString).slice(-7) + "\u00B0";
					}
				}
			}
		});

		// Post rendering
		scene.postUpdate.addEventListener(function (scene, time) {
			if (scene.referenceFrame === "inertial") {
				//Computes a rotation matrix to transform a point or vector from the International Celestial Reference Frame (GCRF/ICRF) inertial frame axes to the Earth-Fixed frame axes (ITRF) at a given time.
				const icrfToFixed = Cesium.Transforms.computeIcrfToFixedMatrix(time);
				if (Cesium.defined(icrfToFixed)) {
					const offset = Cesium.Cartesian3.clone(camera.position);
					const transform = Cesium.Matrix4.fromRotationTranslation(icrfToFixed);
					camera.lookAtTransform(transform, offset);
				}
			}
		});
	}

	// Viewer get/set methods
	setWebsocketId(id) {
		this.viewer.websocketId = id;
	}

	setReferenceFrame(value) {
		this.viewer.scene.referenceFrame = value;
		console.log("[Viewer] Reference frame " + this.viewer.scene.referenceFrame + "\n");
	}

	getWebsocketId() {
		return this.viewer.websocketId;
	}

	getCurrentTime() {
		return this.viewer.clock.currentTime;
	}

	getISOCurrentTime() {
		return Cesium.JulianDate.toIso8601(this.viewer.clock.currentTime);
	}

	getStartTime() {
		return this.viewer.clock.startTime;
	}

	getISOStartTime() {
		return Cesium.JulianDate.toIso8601(this.viewer.clock.startTime);
	}

	getStopTime() {
		return this.viewer.clock.stopTime;
	}

	getISOStopTime() {
		return Cesium.JulianDate.toIso8601(this.viewer.clock.stopTime);
	}

	getCameraFoV() {
		return Cesium.Math.toDegrees(this.viewer.camera.frustum.fov);
	}

	getCameraHeight() {
		return this.viewer.camera.positionCartographic.height;
	}

	getEntity(entityId) {
		let entity;
		if (entityId !== undefined || entityId !== "") {
			for (let i = 0; i < this.viewer.dataSourceDisplay.dataSources.length; i++) {
				const dataSource = this.viewer.dataSourceDisplay.dataSources.get(i);
				for (let j = 0; j < dataSource.entities.values.length; j++) {
					if (dataSource.entities.values[j].id === entityId) {
						entity = dataSource.entities.values[j];
						break;
					}
				}
			}
		}
		if (entity === undefined) {
			entity = this.viewer.entities.getById(entityId);
		}
		return entity;
	}

	getEntityCartesianPosition(entityId) {
		const entity = this.getEntity(entityId);
		if (entity !== undefined) {
			if (entity.position !== undefined) {
				return entity.position.getValue(this.getCurrentTime());
			}
		}
	}

	getEntityCartographicRadiansPosition(entityId) {
		const cartographic = this.getEntityCartesianPosition(entityId);
		if (cartographic !== undefined) {
			return Cesium.Cartographic.fromCartesian(cartographic);
		}
	}

	getEntityCartographicDegreesPosition(entityId) {
		const cartographic = this.getEntityCartographicRadiansPosition(entityId);
		if (cartographic !== undefined) {
			return [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), cartographic.height];
		}
	}

	getEntityOrientation(entityId) {
		const entity = this.getEntity(entityId);
		if (entity !== undefined) {
			if (entity.orientation !== undefined) {
				return entity.orientation.getValue(this.getCurrentTime());
			}
		}
	}

	getEntityHeadingPitchRollRadians(entityId) {
		const orientation = this.getEntityOrientation(entityId);
		if (orientation !== undefined) {
			return Cesium.HeadingPitchRoll.fromQuaternion(orientation);
		}
	}

	getEntityHeadingPitchRollDegrees(entityId) {
		const orientation = this.getEntityHeadingPitchRollRadians(entityId);
		if (orientation !== undefined) {
			return [Cesium.Math.toDegrees(orientation.heading), Cesium.Math.toDegrees(orientation.pitch), Cesium.Math.toDegrees(orientation.roll)];
		}
	}

	updateEntity(entityId, longitude, latitude, height, h, p, r) {
		const entity = this.getEntity(entityId);
		if (entity !== undefined) {
			const position = Cesium.Cartesian3.fromDegrees(
				longitude,
				latitude,
				height
			);
			const heading = Cesium.Math.toRadians(h);
			const pitch = Cesium.Math.toRadians(p);
			const roll = Cesium.Math.toRadians(r);
			const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
			const orientation = Cesium.Transforms.headingPitchRollQuaternion(
				position,
				hpr
			);
			entity.position = position;
			entity.orientation = orientation;

			console.log("[Viewer] Update entity " + entityId + "\n");
		} else {
			console.log("[Viewer] Could not update entity " + entityId + "\n");
		}
	}

	isRunning() {
		return this.viewer.clock.shouldAnimate;
	}

	// Viewer render methods
	showShadows(bool) {
		this.viewer.shadows = bool;
		console.log("[Viewer] Shadows " + bool + "\n");
	}

	showSkyAtmosphere(bool) {
		this.viewer.scene.skyAtmosphere.show = bool;
		console.log("[Viewer] Sky atmosphere " + bool + "\n");
	}

	showGroundAtmosphere(bool) {
		this.viewer.scene.globe.showGroundAtmosphere = bool;
		console.log("[Viewer] Ground atmosphere " + bool + "\n");
	}

	showSkyBox(bool) {
		this.viewer.scene.skyBox.show = bool;
		console.log("[Viewer] Skybox " + bool + "\n");
	}

	showMoon(bool) {
		this.viewer.scene.moon.show = bool;
		console.log("[Viewer] Moon " + bool + "\n");
	}

	showDebug(bool) {
		this.viewer.scene.debugShowFramesPerSecond = bool;
		console.log("[Viewer] Debug " + bool + "\n");
	}

	enableFog(bool) {
		this.viewer.scene.fog.enabled = bool;
		console.log("[Viewer] Fog " + bool + "\n");
	}

	enableLensFlare(bool) {
		if (bool) {
			this.viewer.lensflare = Cesium.PostProcessStageLibrary.createLensFlareStage();
			this.viewer.lensflare.uniforms.intensity = 2.0;
			this.viewer.lensflare.uniforms.distortion = 10.0;
			this.viewer.lensflare.uniforms.ghostDispersal = 0.4;
			this.viewer.lensflare.uniforms.haloWidth = 0.4;
			this.viewer.lensflare.uniforms.dirtAmount = 0;
			this.viewer.lensflare.uniforms.earthRadius = Cesium.Ellipsoid.WGS84.maximumRadius;
			this.viewer.scene.postProcessStages.add(this.viewer.lensflare);
		} else {
			this.viewer.scene.postProcessStages.remove(this.viewer.lensflare);
			Cesium.destroyObject(this.viewer.lensflare);
		}
		console.log("[Viewer] Lens flare " + bool + "\n");
	}

	enableFxaa(bool) {
		this.viewer.scene.postProcessStages.fxaa.enabled = bool;
		console.log("[Viewer] FXAA " + bool + "\n");
	}

	enableHdr(bool) {
		this.viewer.scene.highDynamicRange = bool;
		console.log("[Viewer] HDR " + bool + "\n");
	}

	enableLighting(bool) {
		this.viewer.scene.globe.enableLighting = bool;
		console.log("[Viewer] Lightning " + bool + "\n");
	}

	msaa(value) {
		if (this.viewer.scene.msaaSupported) {
			if (value === 2 || value === 4 || value === 8) {
				this.viewer.scene.msaaSamples = value;
				console.log("[Viewer] MSAA enabled with sample " + value + "\n");
			} else {
				this.viewer.scene.msaaSamples = 1;
				console.log("[Viewer] MSAA disabled \n");
			}
		} else {
			console.log("[Viewer] WebGL 2 not supported, MSAA could not be enabled \n");
		}
	}

	scene(type) {
		switch (type) {
			case "3d":
				this.viewer.scene.morphTo3D(2.0);
				break;

			case "2d":
				this.viewer.scene.morphTo2D(2.0);
				break;

			case "columbus":
				this.viewer.scene.morphToColumbusView(2.0);
				break;

			default:
				this.viewer.scene.morphTo3D(2.0);
				break;
		}
		this.cameraReset();
		console.log("[Viewer] Change scene mode to " + type + "\n");
	}

	cartography(name) {
		const layers = this.viewer.scene.imageryLayers;
		layers.removeAll(true);

		const cartoValue = this.viewer.cartography.get(name);
		this.enableLighting(true);
		this.showGroundAtmosphere(true);

		switch (cartoValue[0]) {
			case "cesium":
				layers.addImageryProvider(
					new Cesium.TileMapServiceImageryProvider({
						url: Cesium.buildModuleUrl(cartoValue[1]),
					})
				);
				break;

			case "local":
				layers.addImageryProvider(
					new Cesium.TileMapServiceImageryProvider({
						url: cartoValue[1],
					})
				);
				break;

			case "ion":
				layers.addImageryProvider(
					new Cesium.IonImageryProvider({
						assetId: Number(cartoValue[1])
					})
				);
				break;

			case "osm":
				this.enableLighting(false);
				this.showGroundAtmosphere(false);
				const osm = layers.addImageryProvider(
					new Cesium.OpenStreetMapImageryProvider({
						enablePickFeatures: false,
						url: cartoValue[1]
					})
				);

				osm.brightness = 0.7;
				osm.contrast = 2;
				osm.hue = 0.0;
				osm.saturation = 0.0;
				osm.gamma = 0.8;
				break;

			case "dynamic":
				layers.addImageryProvider(
					new Cesium.IonImageryProvider({ assetId: 3845 })
				);

				const blackMarble = layers.addImageryProvider(new Cesium.IonImageryProvider({ assetId: 3812 }));
				blackMarble.dayAlpha = 0.0;
				blackMarble.contrast = 1.2;
				blackMarble.brightness = 2.0;
				blackMarble.gamma = 1.5;
				break;

			default:
				layers.addImageryProvider(
					new Cesium.TileMapServiceImageryProvider({
						url: Cesium.buildModuleUrl("./Assets/Textures/NaturalEarthII"),
					})
				);
				break;
		}

		const grid = layers.addImageryProvider(new Cesium.GridImageryProvider({
			cells: 5
		}));
		grid.alpha = 0.05;
		grid.gamma = 2.0;
		grid.brightness = 1.5;

		console.log("[Viewer] Change cartography to " + name + "\n");
	}

	terrain(type) {
		Cesium.destroyObject(this.viewer.terrainProvider);

		switch (type) {
			case "default":
				this.viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider();
				break;

			case "height":
				this.viewer.terrainProvider = Cesium.createWorldTerrain();
				break;

			case "normals":
				this.viewer.terrainProvider = Cesium.createWorldTerrain({
					requestVertexNormals: true
				});
				break;

			case "water":
				this.viewer.terrainProvider = Cesium.createWorldTerrain({
					requestWaterMask: true
				});
				break;

			case "waternormals":
				this.viewer.terrainProvider = Cesium.createWorldTerrain({
					requestVertexNormals: true,
					requestWaterMask: true
				});
				break;

			default:
				this.viewer.terrainProvider = Cesium.createWorldTerrain();
				break;
		}
		console.log("[Viewer] Change map effect to " + type + " mask\n");
	}

	enableRequestRenderMode(bool) {
		this.viewer.scene.requestRenderMode = bool;
		console.log("[Viewer] Request render mode " + bool + " \n");
	}

	resolutionScale(value) {
		this.viewer.resolutionScale = value;
		console.log("[Viewer] Resolution scale " + value + " \n");
	}

	targetedFramerate(value) {
		this.viewer.targetFrameRate = value;
		console.log("[Viewer] Targeted framerate " + value + " \n");
	}

	maximumRenderTimeChange(value) {
		this.viewer.scene.maximumRenderTimeChange = value;
		console.log("[Viewer] Maximum render time " + value + " \n");
	}

	showEntities(bool, entitiesList) {
		for (let i = 0; i < entitiesList.length; i++) {
			const entity = this.viewer.entities.getById(entitiesList[i]);
			if (entity !== undefined) {
				entity.show = bool;
			}
		}
		console.log("[Viewer] Show entities " + bool + " \n");
	}

	showCartoPosition(bool, element) {
		this.viewer.scene.cartoElement = element;
		this.viewer.scene.cartoPositionBool = bool;
		console.log("[Viewer] Show cartographic coordinates " + bool + " \n");
	}

	enableDepthTestAgainstTerrain(bool) {
		this.viewer.scene.globe.depthTestAgainstTerrain = bool;
		console.log("[Viewer] Depth test against terrain " + bool + " \n");
	}

	// Viewer methods
	cameraReset() {
		this.viewer.trackedEntity = undefined;
		this.cameraFoV(60);
		this.viewer.camera.flyTo({
			destination: this.viewer.home
		});
		console.log("[Viewer] Reset camera \n");
	}

	cameraOrientation(heading, pitch, roll) {
		this.viewer.camera.setView({
			orientation: {
				heading: Cesium.Math.toRadians(heading),
				pitch: Cesium.Math.toRadians(pitch),
				roll: Cesium.Math.toRadians(roll)
			}
		});
		console.log("[Camera] Update camera orientation (in degrees) to " + heading + " " + pitch + " " + roll + "\n");
	}

	cameraPosition(longitude, latitude, height) {
		this.viewer.camera.flyTo({
			destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height)
		});
		console.log("[Camera] Update camera position to " + longitude + " " + latitude + " " + height + "\n");
	}

	cameraFoV(value) {
		this.viewer.camera.frustum.fov = Cesium.Math.toRadians(value);
		console.log("[Viewer] Camera FOV " + value + "\n");
	}

	cameraMoveForward(heightInMeters) {
		this.viewer.camera.moveForward(heightInMeters);
		console.log("[Camera] Update camera heigh to " + this.viewer.camera.positionCartographic.height + " meters \n");
	}

	cameraMoveBackward(heightInMeters) {
		this.viewer.camera.moveBackward(heightInMeters);
		console.log("[Camera] Update camera heigh to " + this.viewer.camera.positionCartographic.height + " meters \n");
	}

	play(value) {
		this.viewer.clock.shouldAnimate = value;
		console.log("[Viewer] Play " + value + "\n");
	}

	tick(value) {
		if (!this.viewer.clock.shouldAnimate) {
			const newDate = new Cesium.JulianDate();
			Cesium.JulianDate.addSeconds(this.viewer.clock.currentTime, value * 1, newDate);
			this.viewer.clock.currentTime = newDate;
			Cesium.destroyObject(newDate);
		}
	}

	timeManagement(value) {
		this.viewer.clock.canAnimate = value;
		this.viewer.clock.shouldAnimate = value;
		console.log("[Viewer] Time management by Cesium " + value + " \n");
	}

	clockReset() {
		this.viewer.clock.currentTime = Cesium.JulianDate.now();

		const startTime = new Cesium.JulianDate();
		Cesium.JulianDate.addDays(Cesium.JulianDate.now(), -1, startTime);
		this.viewer.clock.startTime = startTime;

		const stopTime = new Cesium.JulianDate();
		Cesium.JulianDate.addDays(Cesium.JulianDate.now(), 1, stopTime);
		this.viewer.clock.stopTime = stopTime;

		this.viewer.clock.multiplier = 1.0;
		this.viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER;

		if (this.timeline !== undefined) {
			this.timeline.zoomTo(this.viewer.clock.startTime, this.viewer.clock.stopTime);
		}

		Cesium.destroyObject(startTime);
		Cesium.destroyObject(stopTime);
		console.log("[Viewer] Reset clock\n");
	}

	clockDate(value) {
		const newDate = new Cesium.JulianDate();
		Cesium.JulianDate.clone(value, newDate);
		this.viewer.clock.currentTime = newDate;

		Cesium.destroyObject(newDate);
		console.log("[Viewer] Clock date " + value + "\n");
	}

	clockISODate(value) {
		const newDate = new Cesium.JulianDate();
		Cesium.JulianDate.fromIso8601(value, newDate);
		this.viewer.clock.currentTime = newDate;

		Cesium.destroyObject(newDate);
		console.log("[Viewer] Clock ISO date " + value + "\n");
	}

	clockISODateStartStop(dateRange) {
		const dates = dateRange.split("/");
		if (dates[0] !== undefined && dates[1] !== undefined) {
			if (dates[0] !== "" && dates[1] !== "") {
				const startDate = new Cesium.JulianDate();
				const stopDate = new Cesium.JulianDate();

				Cesium.JulianDate.fromIso8601(dates[0], startDate);
				Cesium.JulianDate.fromIso8601(dates[1], stopDate);

				this.viewer.clock.startTime = startDate;
				this.viewer.clock.stopTime = stopDate;

				this.updateTimeline(this.viewer.clock.currentTime, startDate, stopDate);
				this.resizeTimeline();

				Cesium.destroyObject(startDate);
				Cesium.destroyObject(stopDate);
				console.log("[Viewer] Clock ISO date (start) " + dates[0] + " | Clock ISO date (stop) " + dates[1] + "\n");
			} else {
				console.log("[Viewer] Not valid start or stop date \n");
			}
		} else {
			console.log("[Viewer] Missing start or stop date \n");
		}
	}

	clockMultiplier(value) {
		this.viewer.clock.multiplier = value;
		console.log("[Viewer] Clock multiplier " + value + "\n");
	}

	getClockMultiplier() {
		return this.viewer.clock.multiplier;
	}

	resizeTimeline() {
		if (this.timeline !== undefined) {
			this.timeline.resize();
		}
	}

	updateTimeline(date, start = undefined, end = undefined) {
		let currentTime = new Cesium.JulianDate();
		if (typeof date === "string" && date.indexOf("Z") > -1) {
			currentTime = Cesium.JulianDate.fromIso8601(date, currentTime);
		} else {
			currentTime = date;
		}

		let startTime = new Cesium.JulianDate();
		let stopTime = new Cesium.JulianDate();

		if (start === undefined) {
			startTime = Cesium.JulianDate.addDays(currentTime, 0, startTime);
		} else {
			startTime = Cesium.JulianDate.clone(start, startTime);
		}

		if (end === undefined) {
			stopTime = Cesium.JulianDate.addDays(currentTime, 1, stopTime);
		} else {
			stopTime = Cesium.JulianDate.clone(end, stopTime);
		}

		if (this.timeline !== undefined) {
			this.timeline.zoomTo(startTime, stopTime);
		}

		Cesium.destroyObject(startTime);
		Cesium.destroyObject(stopTime);
		Cesium.destroyObject(currentTime);
		console.log("[Viewer] Update timeline\n");
	}

	addDataSource(dataSource, zoom = false) {
		if (!this.viewer.dataSources.contains(dataSource)) {
			this.viewer.dataSources.add(dataSource);
			if (zoom) {
				this.viewer.zoomTo(dataSource);
			}
			console.log("[Viewer] Add datasource " + dataSource.name + " \n");
		}
	}

	flyToDataSource(dataSource) {
		this.viewer.flyTo(dataSource);
		console.log("[Viewer] Fly to datasource " + dataSource.name + " \n");
	}

	removeDataSource(dataSource) {
		if (this.viewer.dataSources.contains(dataSource)) {
			this.viewer.dataSources.remove(dataSource);
			console.log("[Viewer] Remove datasource " + dataSource.name + " \n");
		}
	}

	trackEntity(entity) {
		if (entity !== undefined) {
			console.log("[Viewer] Track entity " + entity.id + " \n");
		} else {
			if (this.viewer.trackedEntity !== undefined) {
				console.log("[Viewer] Untrack entity \n");
			}
			else {
				console.log("[Viewer] No entity to track or untrack \n");
			}
		}
		this.viewer.trackedEntity = entity;
	}

	playKmlTour(kmlTour) {
		kmlTour.play(this.viewer);
		this.viewer.kmlTour = kmlTour;
		console.log("[Viewer] Play Kml tour " + kmlTour.id + " \n");
	}

	stopKmlTour() {
		if (this.viewer.kmlTour !== undefined) {
			this.viewer.kmlTour.stop();
			this.viewer.kmlTour = undefined;
			console.log("[Viewer] Stop Kml tour \n");
		} else {
			console.log("[Viewer] No Kml tour to stop \n");
		}
	}

	addActor(actorJson) {
		this.volume.addActor(actorJson);
	}

	updateActor(actorJson) {
		this.volume.updateActor(actorJson);
	}

	removeEntities(entitiesId) {
		for (let i = 0; i < entitiesId.length; i++) {
			const entity = this.getEntity(entitiesId[i]);
			Cesium.destroyObject(entity);
		}
	}

	removeStreamEntities(entitiesId) {
		this.volume.removeEntities(entitiesId);
	}

	showVolumeStreamedEntity(entityId, bool) {
		this.volume.showActorChildren(entityId, bool);
	}
}

Thanks you for your help !
Emmanuel.

Thanks Emmanuel!

I believe the issue is due to a problem with Cesium.GridImageryProvider.requestImage. The result returned by this function was not matching the type specified in the documentation (a Promise or undefined).

I just opened a fix for that issue in Fix requestImagery return types by ggetz · Pull Request #10268 · CesiumGS/cesium · GitHub. If you could, please try it out when you get the chance and hopefully that fixes your issue here.

Thanks you a lot Gabby :slight_smile:

I will try it out as soon as possible!