How to swap imagery providers on error

hi all,

Is there an easy way to swap my imagery provider for a different imagery provider if the first throws an error?

E.G.: My map loads with imagery from Bing; if for whatever reason it can’t access imagery from Bing (I typed in my key wrong, whatever), I’d like it to access imagery from a USGS server.

You can use the imageryProvider’s readyPromise to listen for whether it was successfully created, and if not, you can remove it and add a different layer. Luckily there is one failing Bing layer in Sandcastle we can use to test:

var imageryProvider = new Cesium.BingMapsImageryProvider({

url : ‘’,

mapStyle : Cesium.BingMapsStyle.ROAD


var viewer = new Cesium.Viewer(‘cesiumContainer’, {

imageryProvider: imageryProvider


imageryProvider.readyPromise.then(function() {



.otherwise(function(error) {


// Remove the first layer:


// Add a different one:

viewer.imageryLayers.addImageryProvider(new Cesium.IonImageryProvider({ assetId: 3845 }));



Live Sandcastle link.

Thanks Omar, you’re a lifesaver.