mousewheel zooms on mouse position. patch from #341. thanks frederic \!

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1945 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-11-21 09:32:13 +00:00
parent c951391368
commit 15c2ab578f

View File

@@ -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);
}
}