4

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?

4 Answers 4

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) {
       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);
3

Try the stopClick option

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

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;
   }
});
0

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

ol.interaction.defaults({
    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 you have read our privacy policy.

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