Files
openlayers/src/ol/interaction/doubleclickzoominteraction.js
Éric Lemoine a85b82090d 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.
2013-10-30 13:16:09 +01:00

62 lines
1.6 KiB
JavaScript

// FIXME works for View2D only
goog.provide('ol.interaction.DoubleClickZoom');
goog.require('goog.asserts');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEvent.EventType');
goog.require('ol.interaction.Interaction');
/**
* Allows the user to zoom by double-clicking on the map.
*
* @constructor
* @extends {ol.interaction.Interaction}
* @param {ol.interaction.DoubleClickZoomOptions=} opt_options Options.
* @todo stability experimental
*/
ol.interaction.DoubleClickZoom = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
/**
* @private
* @type {number}
*/
this.delta_ = goog.isDef(options.delta) ? options.delta : 1;
goog.base(this);
/**
* @private
* @type {number}
*/
this.duration_ = goog.isDef(options.duration) ? options.duration : 250;
};
goog.inherits(ol.interaction.DoubleClickZoom, ol.interaction.Interaction);
/**
* @inheritDoc
*/
ol.interaction.DoubleClickZoom.prototype.handleMapBrowserEvent =
function(mapBrowserEvent) {
var stopEvent = false;
var browserEvent = mapBrowserEvent.browserEvent;
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK) {
var map = mapBrowserEvent.map;
var anchor = mapBrowserEvent.getCoordinate();
var delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
// FIXME works for View2D only
var view = map.getView().getView2D();
ol.interaction.Interaction.zoomByDelta(
map, view, delta, anchor, this.duration_);
mapBrowserEvent.preventDefault();
stopEvent = true;
}
return !stopEvent;
};