openlayers-3

Mouse wheel zoom limitation in OpenLayers 3


I know that the OpenLayers 3 ol.interaction.MouseWheelZoom accumulates mouse wheel events for an amount of time before it actually fires the event, which is a wanted behavior. However it seems that it limits the maximum zoom step to a constant range. This can be seen in the following function:

/**
* @private
* @param {ol.Map} map Map.
*/
ol.interaction.MouseWheelZoom.prototype.doZoom_ = function(map) {
    var maxDelta = ol.MOUSEWHEELZOOM_MAXDELTA;
    var delta = goog.math.clamp(this.delta_, -maxDelta, maxDelta);

    var view = map.getView();

    goog.asserts.assert(!goog.isNull(view));
    map.render();

    ol.interaction.Interaction.zoomByDelta(map, view, -delta,
        this.lastAnchor_,
        this.duration_);

    this.delta_ = 0;
    this.lastAnchor_ = null;
    this.startTime_ = undefined;
    this.timeoutId_ = undefined;
};

taken from https://github.com/openlayers/ol3/blob/master/src/ol/interaction/mousewheelzoominteraction.js

In my application this is an unwanted feature, as the user needs to be able to zoom as much and as quickly as possible. Is there a way to overcome this limitation e.g. by building a custom interaction or altering my map configuration somehow?


Solution

  • Currently the max delta can only be configured through a compiler define when creating a custom build.

    To achieve this, you will want something like this in your build configuration (here: a max delta of 10):

    “define”: [
      “ol.MOUSEWHEELZOOM_MAXDELTA=10”
    ]
    

    See https://github.com/openlayers/ol3/blob/master/tasks/readme.md if you need more general information on build configurations and the build task.