0

In OpenLayers 2 one can specify a pixelTolerance setting in the Click handler. If the map is moved by less than or equal to this number of pixels a click event is also fired.

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {  
    defaultHandlerOptions: {  
        'pixelTolerance': 20,  
        ...  
    },  
    ...  
}

Question: Is there anything similar in OpenLayers 3?

Kaspar Lee
  • 5,446
  • 4
  • 31
  • 54
Derek
  • 345
  • 3
  • 15

1 Answers1

0

You can achieve this listening if map is dragging:

map.on('pointermove', function(evt) {
  if (evt.dragging) {
    console.info('dragging');
  }
});

// another option
map.on('pointerdrag', function(evt) {
  console.info('pointerdrag');
  console.info(evt);
});
Jonatas Walker
  • 13,583
  • 5
  • 53
  • 82
  • I don't see how to apply this to acheive what OL2 does. With mousedown and mouseup pixel coordinates I can use pythagorus to calculate how many pixels the map has moved and use: `if (pixelsMoved <= 20) { map.dispatchEvent('click'); }`. My problem is this iterferes with other mouse events. – Derek Mar 16 '16 at 13:42
  • Why don't you put your logic inside `pointerdrag` event, instead dispatching `click` event? – Jonatas Walker Mar 16 '16 at 14:29
  • How do I get a "dragstart" and "dragend"? – Derek Mar 17 '16 at 07:24
  • Set a `boolean` variable at start of `pointerdrag` and listen to `map.on('moveend', someFunction)` – Jonatas Walker Mar 17 '16 at 09:52
  • Not sure how to work with that on what the question is asking. I found a similiar Question that seems to have a answer fitting what i had in mind: https://stackoverflow.com/questions/43693272/openlayers-3-set-sensitivity-on-drag-map – icyerasor Sep 27 '21 at 17:18