the mousewheel handler zooms the map by default
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* @fileoverview Map Mouse Wheel Handler.
|
* @fileoverview Mouse Wheel Handler.
|
||||||
*
|
*
|
||||||
* Provides a class for listening to mousewheel events on a DOM element
|
* Provides a class for listening to mousewheel events on a DOM element
|
||||||
* and re-dispatching to a map instance.
|
* and re-dispatching to a map instance.
|
||||||
|
*
|
||||||
|
* The default behabior is zooming the map.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
goog.provide('ol.handler.MouseWheel');
|
goog.provide('ol.handler.MouseWheel');
|
||||||
@@ -34,7 +36,39 @@ ol.handler.MouseWheel = function(map, elt) {
|
|||||||
|
|
||||||
goog.events.listen(handler,
|
goog.events.listen(handler,
|
||||||
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL,
|
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL,
|
||||||
handleMouseWheel);
|
this.handleMouseWheel, false, this);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.handler.MouseWheel, goog.Disposable);
|
goog.inherits(ol.handler.MouseWheel, goog.Disposable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {goog.events.MouseWheelEvent} e
|
||||||
|
*/
|
||||||
|
ol.handler.MouseWheel.prototype.handleMouseWheel = function(e) {
|
||||||
|
e.position = goog.style.getRelativePosition(e, this.elt_);
|
||||||
|
e.type = 'mousewheel';
|
||||||
|
var rt = goog.events.dispatchEvent(this.map_, e);
|
||||||
|
if (rt) {
|
||||||
|
this.defaultBehavior(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {goog.events.MouseWheelEvent} e
|
||||||
|
*/
|
||||||
|
ol.handler.MouseWheel.prototype.defaultBehavior = function(e) {
|
||||||
|
var me = this;
|
||||||
|
if (e.deltaY === 0 || me.zoomBlocked_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
me.zoomBlocked_ = window.setTimeout(function() {
|
||||||
|
me.zoomBlocked_ = null;
|
||||||
|
}, 200);
|
||||||
|
|
||||||
|
var map = me.map_,
|
||||||
|
step = e.deltaY / Math.abs(e.deltaY);
|
||||||
|
map.setZoom(map.getZoom() - step, e.position);
|
||||||
|
|
||||||
|
// We don't want the page to scroll.
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user