Setting isBaseLayer to true on added layer?

I currently have this function for adding base layers:

function addBaseLayerOption(name, imageryProvider, alpha, show) {
  var layer = imageryLayerCollection.addImageryProvider(imageryProvider);
  layer.alpha = Cesium.defaultValue(alpha, 0);
  layer.show = Cesium.defaultValue(show, true);
  layer.name = name;
}

When these layers are being added however they are not being set to isBaseLayer true. How can I set it so that each layer that is added the isBaseLayer is set to true?

Hi Adam,

Only one layer (the base one) can be the base layer. What are you actually trying to do?

Kevin

I have managed to get around this problem but have hit another in doing this. I have an application which starts up and when it does places a layer on the globe for example:

var blackMarble = layers.addImageryProvider(new Cesium.TileMapServiceImageryProvider({
    url : ‘http://cesium.agi.com/blackmarble’,
    maximumLevel : 8,
    credit : ‘Black Marble imagery courtesy NASA Earth Observatory’
}));

I then have my own toolbox of buttons for different layers to add. When a button is clicked then a new layer is added and the starting layer is removed like so:

    function addBaseLayerOption(name, imageryProvider, alpha, show) {
      var layer = imageryLayerCollection.addImageryProvider(imageryProvider, 1);
      layer.alpha = Cesium.defaultValue(alpha, 0);
      layer.show = Cesium.defaultValue(show, true);
      layer.name = name;
      var layer2 = imageryLayerCollection.get(0);
      imageryLayerCollection.remove(layer2);
    }

However the layer is then not displayed and all that is displayed is plain blue view on the globe as if there are no layers. I have check in Chrome dev tools in the imageryLayerCollection and the layer is there and isBaseLayer is true so by my understanding the layer should be displayed should it not?

Not to worry I have managed to solve this.

Hi, it has been some time since your post, but i have the same exact problem (using my own tools to manage the layers), when i set show to false for one layer and another to true, the globe just stays blue, without requesting the new tiles. If a switch one more time curiously it loads the tiles.
From what i can see i create the layers pretty much as you did.

how did you solve this?

Hi, managed to solve the problem. It was my fault, when setting the show property of the layer i used a wrong getter and i imagine it was undefined. When i set the show value of each layer correctly it worked as expected.

Kind regards!