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:
@@ -94,6 +94,9 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
* @param {Event} evt
|
* @param {Event} evt
|
||||||
*/
|
*/
|
||||||
defaultMouseMove: function (evt) {
|
defaultMouseMove: function (evt) {
|
||||||
|
// record the mouse position, used in onWheelEvent
|
||||||
|
this.mousePosition = evt.xy.clone();
|
||||||
|
|
||||||
if (this.mouseDragStart != null) {
|
if (this.mouseDragStart != null) {
|
||||||
if (this.zoomBox) {
|
if (this.zoomBox) {
|
||||||
var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
|
var deltaX = Math.abs(this.mouseDragStart.x - evt.xy.x);
|
||||||
@@ -155,15 +158,21 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
/** User spun scroll wheel up
|
/** User spun scroll wheel up
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
defaultWheelUp: function() {
|
defaultWheelUp: function(evt) {
|
||||||
this.map.zoomIn();
|
if (this.map.getZoom() <= this.map.getNumZoomLevels()) {
|
||||||
|
this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
|
||||||
|
this.map.getZoom() + 1);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/** User spun scroll wheel down
|
/** User spun scroll wheel down
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
defaultWheelDown: function() {
|
defaultWheelDown: function(evt) {
|
||||||
this.map.zoomOut();
|
if (this.map.getZoom() > 0) {
|
||||||
|
this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
|
||||||
|
this.map.getZoom() - 1);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Zoombox function.
|
/** Zoombox function.
|
||||||
@@ -238,10 +247,15 @@ OpenLayers.Control.MouseDefaults.prototype =
|
|||||||
delta = -e.detail / 3;
|
delta = -e.detail / 3;
|
||||||
}
|
}
|
||||||
if (delta) {
|
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) {
|
if (delta < 0) {
|
||||||
this.defaultWheelDown();
|
this.defaultWheelDown(e);
|
||||||
} else {
|
} else {
|
||||||
this.defaultWheelUp();
|
this.defaultWheelUp(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user