The accepted answer assumes that the zoom control is on the map. If visualEnabled is false, the dragzoom_btn image will not exist.
A hack that seems to work:
function onZoomClick() { var myKeyDragZoom = map.getDragZoomObject(); myKeyDragZoom.hotKeyDown_ = !myKeyDragZoom.hotKeyDown_; }
When pressed, the zoom mode is activated. When you press or draw a rectangle again, the zoom mode is automatically turned off.
source share