Removing terrain data

I have an on/off button that I want to use to be able to switch the terrain data on and off. It currently works when turning on the data but I am not too sure how to remove it. Is there a way I can achieve this? Below is the code I have:

  function onoff(){
  currentvalue = document.getElementById('onoff').value;
  if(currentvalue == "Off"){
  // Remove goes here...
  viewer.screenSpaceEventHandler.setInputAction(function(movement) {
        var pickedPrimitive = viewer.scene.pick(movement.endPosition);
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

    createPrimitives1(viewer.scene, viewer.centralBody.getEllipsoid());
  var terrainProvider = new Cesium.CesiumTerrainProvider({
    url : ‘
viewer.centralBody.terrainProvider = terrainProvider;


You can disable terrain by assigning a default-constructed EllipsoidTerrainProvider.


That technique worked thank you very much!