Code coverage report for ol/interaction/mousewheelzoominteraction.js

Statements: 48.89% (22 / 45)      Branches: 37.5% (3 / 8)      Functions: 66.67% (2 / 3)      Lines: 48.89% (22 / 45)      Ignored: none     

All files » ol/interaction/ » mousewheelzoominteraction.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 1221   1 1 1 1 1 1 1                         1   81       81           81           81           81           81           81     1                     1 169 169                                               169               1                                
goog.provide('ol.interaction.MouseWheelZoom');
 
goog.require('goog.asserts');
goog.require('goog.events.MouseWheelEvent');
goog.require('goog.events.MouseWheelHandler.EventType');
goog.require('goog.math');
goog.require('ol');
goog.require('ol.Coordinate');
goog.require('ol.interaction.Interaction');
 
 
 
/**
 * @classdesc
 * Allows the user to zoom the map by scrolling the mouse wheel.
 *
 * @constructor
 * @extends {ol.interaction.Interaction}
 * @param {olx.interaction.MouseWheelZoomOptions=} opt_options Options.
 * @api stable
 */
ol.interaction.MouseWheelZoom = function(opt_options) {
 
  goog.base(this, {
    handleEvent: ol.interaction.MouseWheelZoom.handleEvent
  });
 
  var options = goog.isDef(opt_options) ? opt_options : {};
 
  /**
   * @private
   * @type {number}
   */
  this.delta_ = 0;
 
  /**
   * @private
   * @type {number}
   */
  this.duration_ = goog.isDef(options.duration) ? options.duration : 250;
 
  /**
   * @private
   * @type {?ol.Coordinate}
   */
  this.lastAnchor_ = null;
 
  /**
   * @private
   * @type {number|undefined}
   */
  this.startTime_ = undefined;
 
  /**
   * @private
   * @type {number|undefined}
   */
  this.timeoutId_ = undefined;
 
};
goog.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction);
 
 
/**
 * Handles the {@link ol.MapBrowserEvent map browser event} (if it was a
 * mousewheel-event) and eventually zooms the map.
 * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
 * @return {boolean} `false` to stop event propagation.
 * @this {ol.interaction.MouseWheelZoom}
 * @api
 */
ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
  var stopEvent = false;
  Iif (mapBrowserEvent.type ==
      goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) {
    var map = mapBrowserEvent.map;
    var mouseWheelEvent = mapBrowserEvent.browserEvent;
    goog.asserts.assertInstanceof(mouseWheelEvent, goog.events.MouseWheelEvent,
        'mouseWheelEvent should be of type MouseWheelEvent');
 
    this.lastAnchor_ = mapBrowserEvent.coordinate;
    this.delta_ += mouseWheelEvent.deltaY;
 
    if (!goog.isDef(this.startTime_)) {
      this.startTime_ = goog.now();
    }
 
    var duration = ol.MOUSEWHEELZOOM_TIMEOUT_DURATION;
    var timeLeft = Math.max(duration - (goog.now() - this.startTime_), 0);
 
    goog.global.clearTimeout(this.timeoutId_);
    this.timeoutId_ = goog.global.setTimeout(
        goog.bind(this.doZoom_, this, map), timeLeft);
 
    mapBrowserEvent.preventDefault();
    stopEvent = true;
  }
  return !stopEvent;
};
 
 
/**
 * @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), 'view should not be null');
 
  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;
};