I am trying to remove custom draw controls from my OpenLayers application which I create like this:

var drawControls = {
     polygon: new OpenLayers.Control.DrawFeature(polygonLayerFreehand, OpenLayers.Handler.Polygon),
     select: selectControl,
     box: new OpenLayers.Control.DrawFeature(boxLayer,
          OpenLayers.Handler.RegularPolygon, {
            handlerOptions: {
                sides: 4,
                irregular: true

and which I add to the map like this:

for(var key in drawControls) {

I now would like to know how I can remove this custom control. I found examples for removing the standard OL controls like e.g. this

var ovMapControl = _map.getControlsBy("CLASS_NAME", "OpenLayers.Control.OverviewMap")[0];


var ovMapControl = _map.getControlsBy('displayClass','olControlPanZoomBar')[0];

but what is the 'displayClass' or the 'CLASS_NAME' in the case of custom controls like my 'drawControls'?


Assume you still have access to drawControls object at the place you want to remove the controls, then you can do something like:

for (var key in drawControls){

You can simply remove control by using


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.