Refactoring to set the constraints to the map

This commit is contained in:
Éric Lemoine
2012-09-26 23:28:01 +02:00
parent 2991fa1178
commit b6bb05bf76
15 changed files with 164 additions and 178 deletions
+10 -11
View File
@@ -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();
}
};