How can I remove standard controls in an OpenLayers-Map?

Traverse the array of controls and then remove the zoom control

map.getControls().forEach(function(control) {
  if (control instanceof ol.control.Zoom) {
    map.removeControl(control);
  }
}, this);

The map object has a property called controls that is an array of OpenLayers.Control objects. If this property is not explicitly set then OpenLayers will assume that you want the default control set, including OpenLayers.Control.Navigation(), OpenLayers.Control.PanZoom(), OpenLayers.Control.ArgParser(), and OpenLayers.Control.Attribution().

To remove PanZoom or any other default control, simply set the controls property array at the time you construct the Map object. Here is a code example:

var map = new OpenLayers.Map('map', {
    controls: [
        new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.ArgParser(),
        new OpenLayers.Control.Attribution()
    ]
});

Here is a live example.

Please note that by setting the controls property that you will not get any Control objects be default. Any controls you need must be added manually.

Here is a link to the source code of the Map object if you want to see how it works for yourself.


I would have expected map.removeControl(OpenLayers.Control.PanZoom) to work but apparently not.