I'm using OpenLayers-3.8.2. I have a draw Ineraction as follow:

function drawEnd(){
var drawInteraction = new ol.interaction.Draw({
   source: mysource,
   type: 'LineString'
drawInteraction.on('drawend', drawEnd);

I want to user draw just one feature. This Code work, but when user draw a feature, map zoom in 2 level.

How can I prevent zooming in?

4 Answers 4


The proper way to handle this is something like:

// Find the double click interaction that is on the map.
var dblclickzoom;
map.getInteractions().forEach(function (interaction) {
   if (interaction instanceof ol.interaction.DoubleClickZoom) {

// Remove the interaction from the map.
if (dblclickzoom) { map.removeInteraction(dblclickzoom); }

/* Add your draw interaction here */
var drawinteraction=new ol.interaction.Draw(...);

// I like to stick the listener on the source's change event rather than
// the interaction's drawend, but I think either should work...
drawinteraction.on('drawend', function () {
   // Do this in a timeout so it doesn't get triggered by the potential
   // double click that caused the drawing to end.
   if (dblclickzoom) {
       setTimeout(function () {
// Start the draw interaction...

Try the stopClick option

var drawInteraction = new ol.interaction.Draw({
   source: mysource,
   type: 'LineString',
   stopClick: true

You can listen for the dblclick event and then simply return false; to disable the zoom; However you need to set a condition for it so it will disable the zoom only when the user is drawing.

map.on( "dblclick", function (e) {
   if ( drawingMode ) {
       return false;

by setting this before draw you can disable the zoom on double click,

    doubleClickZoom :false

after removing the draw interaction set back the double click zoom to true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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