Emulate click events only on mouse "action"

`click` events are fired only if the mouse action button is pressed. This prevents `click` events from being fired when the middle mouse button is used.

Also, without this commit, in Chrome with emulated touch events enabled, double-clicking the map doesn't zoom the map. This is because `ol.BrowserFeature.HAS_TOUCH` is `false` in that environment. The commit fixes it by testing `isMouseActionButton` on mouse devices only.
This commit is contained in:
Éric Lemoine
2013-10-29 15:58:22 +01:00
parent 0c212fdcb5
commit a85b82090d
2 changed files with 2 additions and 14 deletions

View File

@@ -46,8 +46,7 @@ ol.interaction.DoubleClickZoom.prototype.handleMapBrowserEvent =
function(mapBrowserEvent) {
var stopEvent = false;
var browserEvent = mapBrowserEvent.browserEvent;
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK &&
mapBrowserEvent.isMouseActionButton()) {
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK) {
var map = mapBrowserEvent.map;
var anchor = mapBrowserEvent.getCoordinate();
var delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;

View File

@@ -8,7 +8,6 @@ goog.require('goog.events');
goog.require('goog.events.BrowserEvent');
goog.require('goog.events.EventTarget');
goog.require('goog.events.EventType');
goog.require('ol.BrowserFeature');
goog.require('ol.Coordinate');
goog.require('ol.FrameState');
goog.require('ol.MapEvent');
@@ -76,16 +75,6 @@ ol.MapBrowserEvent.prototype.getPixel = function() {
};
/**
* @return {boolean} Do we have a left click?
*/
ol.MapBrowserEvent.prototype.isMouseActionButton = function() {
// always assume a left-click on touch devices
return ol.BrowserFeature.HAS_TOUCH ||
this.browserEvent.isMouseActionButton();
};
/**
* Prevents the default browser action.
* @see https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault
@@ -226,7 +215,7 @@ ol.MapBrowserEventHandler.prototype.handleMouseUp_ = function(browserEvent) {
ol.MapBrowserEvent.EventType.DRAGEND, this.map_, browserEvent);
this.dispatchEvent(newEvent);
this.down_ = null;
} else {
} else if (browserEvent.isMouseActionButton()) {
this.emulateClick_(browserEvent);
}
}