Add mouseWheelZoomDelta option to MapOptions

This commit is contained in:
Éric Lemoine
2012-09-27 15:16:14 +02:00
parent dd425ff922
commit d2f9ebae41
4 changed files with 64 additions and 8 deletions

View File

@@ -9,8 +9,15 @@ goog.require('ol.MapBrowserEvent');
/**
* @constructor
* @extends {ol.interaction.Interaction}
* @param {number} delta The zoom delta applied on each mousewheel.
*/
ol.interaction.MouseWheelZoom = function() {
ol.interaction.MouseWheelZoom = function(delta) {
/**
* @private
* @type {number}
*/
this.delta_ = delta;
goog.base(this);
};
goog.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction);
@@ -28,12 +35,8 @@ ol.interaction.MouseWheelZoom.prototype.handleMapBrowserEvent =
mapBrowserEvent.browserEvent;
goog.asserts.assert(mouseWheelEvent instanceof goog.events.MouseWheelEvent);
var anchor = mapBrowserEvent.getCoordinate();
var oldResolution = map.getResolution();
var factor = Math.exp(Math.log(2) / 4);
if (mouseWheelEvent.deltaY < 0) {
factor = 1 / factor;
}
map.zoomToResolution(oldResolution * factor, anchor);
var delta = mouseWheelEvent.deltaY < 0 ? this.delta_ : -this.delta_;
map.zoom(delta, anchor);
mapBrowserEvent.preventDefault();
mouseWheelEvent.preventDefault();
}

View File

@@ -64,6 +64,7 @@ ol.DEFAULT_RENDERER_HINTS = [
* layers: (ol.Collection|undefined),
* maxResolution: (number|undefined),
* mouseWheelZoom: (boolean|undefined),
* mouseWheelZoomDelta: (number|undefined),
* numZoomLevels: (number|undefined),
* projection: (ol.Projection|string|undefined),
* renderer: (ol.RendererHint|undefined),
@@ -241,7 +242,10 @@ ol.MapOptions.createInteractions_ = function(mapOptionsLiteral) {
var mouseWheelZoom = goog.isDef(mapOptionsLiteral.mouseWheelZoom) ?
mapOptionsLiteral.mouseWheelZoom : true;
if (mouseWheelZoom) {
interactions.push(new ol.interaction.MouseWheelZoom());
var mouseWheelZoomDelta =
goog.isDef(mapOptionsLiteral.mouseWheelZoomDelta) ?
mapOptionsLiteral.mouseWheelZoomDelta : 1;
interactions.push(new ol.interaction.MouseWheelZoom(mouseWheelZoomDelta));
}
var shiftDragZoom = goog.isDef(mapOptionsLiteral.shiftDragZoom) ?