Add new Base layer while removing previous

I have just recently changed from version b20 to b26 having to make a fair few changes to my code to get my cesium app working. I have now resolved most of my issues but one I can't seem to fix is adding a new base layer and then removing the previous layer. This function did work before but now does not:

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

    imageryLayerCollection = viewer.centralBody.imageryLayers;

Can anyone help me out here please?


That code looks about right to me. Are you getting an error in the console, or is it just doing nothing, or what?


Nope no errors in the console. It will add 1 layer fine and in the imageryLayerCollection it adds the layer to position 1 but does not remove the layer at position at 0. When I try another layer after this it seems to place that layer underneath. It is strange behavior and I can't see why it has suddenly stopped working.