diff --git a/lib/OpenLayers/Control/MouseDefaults.js b/lib/OpenLayers/Control/MouseDefaults.js index 296ca28cc1..631b64be8b 100644 --- a/lib/OpenLayers/Control/MouseDefaults.js +++ b/lib/OpenLayers/Control/MouseDefaults.js @@ -94,6 +94,9 @@ OpenLayers.Control.MouseDefaults.prototype = * @param {Event} evt */ defaultMouseMove: function (evt) { + // record the mouse position, used in onWheelEvent + this.mousePosition = evt.xy.clone(); + if (this.mouseDragStart != null) { if (this.zoomBox) { var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x); @@ -155,15 +158,21 @@ OpenLayers.Control.MouseDefaults.prototype = /** User spun scroll wheel up * */ - defaultWheelUp: function() { - this.map.zoomIn(); + defaultWheelUp: function(evt) { + if (this.map.getZoom() <= this.map.getNumZoomLevels()) { + this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), + this.map.getZoom() + 1); + } }, /** User spun scroll wheel down * */ - defaultWheelDown: function() { - this.map.zoomOut(); + defaultWheelDown: function(evt) { + if (this.map.getZoom() > 0) { + this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), + this.map.getZoom() - 1); + } }, /** Zoombox function. @@ -238,10 +247,15 @@ OpenLayers.Control.MouseDefaults.prototype = delta = -e.detail / 3; } if (delta) { + // add the mouse position to the event because mozilla has a bug + // with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179) + // getLonLatFromViewPortPx(e) returns wrong values + e.xy = this.mousePosition; + if (delta < 0) { - this.defaultWheelDown(); + this.defaultWheelDown(e); } else { - this.defaultWheelUp(); + this.defaultWheelUp(e); } }