# Add new Base layer while removing previous

**URL:** <https://community.cesium.com/t/add-new-base-layer-while-removing-previous/1158>\
**Category:** CesiumJS\
**Created:** [April 23, 2014, 9:48am UTC](https://community.cesium.com/t/add-new-base-layer-while-removing-previous/1158 "2014-04-23T09:48:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam.dunnage](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@adam.dunnage](https://community.cesium.com/u/adam.dunnage)\
**Post date:** [April 23, 2014, 9:48am UTC](https://community.cesium.com/t/add-new-base-layer-while-removing-previous/1158/1 "2014-04-23T09:48:44Z")

</div>

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) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var layer = imageryLayerCollection.addImageryProvider(imageryProvider, 1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[//layer.alpha](https://layer.alpha) = Cesium.defaultValue(alpha, 1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layer.show = Cesium.defaultValue(show, true);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layer.name = name;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var layerRemoved = imageryLayerCollection.get(0);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imageryLayerCollection.remove(layerRemoved);  
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;imageryLayerCollection = viewer.centralBody.imageryLayers;

Can anyone help me out here please?

---

<div class="post-metadata">

**Author:** ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)\
**Post date:** [April 23, 2014, 1:22pm UTC](https://community.cesium.com/t/add-new-base-layer-while-removing-previous/1158/2 "2014-04-23T13:22:16Z")

</div>

Hi,

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

Kevin

---

<div class="post-metadata">

**Author:** ![adam.dunnage](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@adam.dunnage](https://community.cesium.com/u/adam.dunnage)\
**Post date:** [April 23, 2014, 1:46pm UTC](https://community.cesium.com/t/add-new-base-layer-while-removing-previous/1158/3 "2014-04-23T13:46:42Z")

</div>

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.
