Refactoring to set the constraints to the map
This commit is contained in:
@@ -3,17 +3,15 @@ goog.provide('ol.interaction.MouseWheelZoom');
|
||||
goog.require('goog.events.MouseWheelEvent');
|
||||
goog.require('goog.events.MouseWheelHandler.EventType');
|
||||
goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.interaction.Constraints');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.interaction.Interaction}
|
||||
* @param {ol.interaction.Constraints} constraints Constraints.
|
||||
*/
|
||||
ol.interaction.MouseWheelZoom = function(constraints) {
|
||||
goog.base(this, constraints);
|
||||
ol.interaction.MouseWheelZoom = function() {
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction);
|
||||
|
||||
@@ -29,13 +27,14 @@ ol.interaction.MouseWheelZoom.prototype.handleMapBrowserEvent =
|
||||
var mouseWheelEvent = /** @type {goog.events.MouseWheelEvent} */
|
||||
mapBrowserEvent.browserEvent;
|
||||
goog.asserts.assert(mouseWheelEvent instanceof goog.events.MouseWheelEvent);
|
||||
if (mouseWheelEvent.deltaY !== 0) {
|
||||
var delta = mouseWheelEvent.deltaY < 0 ? 1 : -1;
|
||||
var resolution = map.getResolution();
|
||||
var anchor = mapBrowserEvent.getCoordinate();
|
||||
this.zoom(map, resolution, delta, anchor);
|
||||
mapBrowserEvent.preventDefault();
|
||||
mouseWheelEvent.preventDefault();
|
||||
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);
|
||||
mapBrowserEvent.preventDefault();
|
||||
mouseWheelEvent.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user