You need to register the DOM event listener addDomListener and call setDrawingMode(null) on the drawingManager .
google.maps.event.addDomListener(document, 'keyup', function (e) { var code = (e.keyCode ? e.keyCode : e.which); if (code === 27) { drawingManager.setDrawingMode(null); } });
Below is a working demo. Hope this helps.
Jsfiddle demo
Edit
I understand that although this works for a rectangle, it does not seem to work with polygons because setting the paint mode to zero actually completes the overlay. In this case, you need to track your overlay (in the overlaycomplete event) and call setMap(null) in the polygon itself in addition to the above.
var polygon; google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) { polygon = e.overlay; }); google.maps.event.addDomListener(document, 'keyup', function (e) { var code = (e.keyCode ? e.keyCode : e.which); if (code === 27) { drawingManager.setDrawingMode(null); polygon.setMap(null); } });
Jsfiddle demo
source share