[GIS] Problem in remove interaction after draw end in openlayers-3

draw-interactionopenlayers

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

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

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?

Best Answer

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) {
       dblclickzoom=interaction;
   }
});

// 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 () {
   map.removeInteraction(drawinteraction);
   // 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 () {
          map.addInteraction(dblclickzoom);
       });
   }
});
// Start the draw interaction...
map.addInteraction(drawinteraction);