With Erik's approval on #341, I'm happy with this. This restores the
mousewheel functionality we had in earlier releases in a similar way, rewritten for handlers. (The benefit of handlers in this case is that handlers are write-once, use many, so the next mousewheel thing we get will *also* be able to use this code.) git-svn-id: http://svn.openlayers.org/trunk/openlayers@2877 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -59,20 +59,33 @@ OpenLayers.Control.Navigation.prototype =
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
wheelChange: function(evt, deltaZ) {
|
||||||
|
var newZoom = this.map.getZoom() + deltaZ;
|
||||||
|
if (!this.map.isValidZoomLevel(newZoom)) return;
|
||||||
|
|
||||||
|
var size = this.map.getSize();
|
||||||
|
var deltaX = size.w/2 - evt.xy.x;
|
||||||
|
var deltaY = evt.xy.y - size.h/2;
|
||||||
|
var newRes = this.map.baseLayer.resolutions[newZoom];
|
||||||
|
var zoomPoint = this.map.getLonLatFromPixel(evt.xy);
|
||||||
|
var newCenter = new OpenLayers.LonLat(
|
||||||
|
zoomPoint.lon + deltaX * newRes,
|
||||||
|
zoomPoint.lat + deltaY * newRes );
|
||||||
|
this.map.setCenter( newCenter, newZoom );
|
||||||
|
},
|
||||||
|
|
||||||
/** User spun scroll wheel up
|
/** User spun scroll wheel up
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
wheelUp: function(evt) {
|
wheelUp: function(evt) {
|
||||||
this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
|
this.wheelChange(evt, 1);
|
||||||
this.map.getZoom() + 1);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/** User spun scroll wheel down
|
/** User spun scroll wheel down
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
wheelDown: function(evt) {
|
wheelDown: function(evt) {
|
||||||
this.map.setCenter(this.map.getLonLatFromPixel(evt.xy),
|
this.wheelChange(evt, -1);
|
||||||
this.map.getZoom() - 1);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ OpenLayers.Handler.MouseWheel.prototype = OpenLayers.Class.inherit( OpenLayers.H
|
|||||||
/** @type function **/
|
/** @type function **/
|
||||||
wheelListener: null,
|
wheelListener: null,
|
||||||
|
|
||||||
|
/** @type OpenLayers.Pixel
|
||||||
|
* @private
|
||||||
|
*
|
||||||
|
* mousePosition is necessary because evt.clientX/Y is buggy in Moz on
|
||||||
|
* wheel events, so we cache and use the value from the last mousemove.
|
||||||
|
**/
|
||||||
|
mousePosition: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*
|
*
|
||||||
@@ -68,8 +76,7 @@ OpenLayers.Handler.MouseWheel.prototype = OpenLayers.Class.inherit( OpenLayers.H
|
|||||||
// add the mouse position to the event because mozilla has a bug
|
// 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)
|
// with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179)
|
||||||
// getLonLatFromViewPortPx(e) returns wrong values
|
// getLonLatFromViewPortPx(e) returns wrong values
|
||||||
// TODO FIXME FIXME this might not be the right way to port the 2.3 behavior
|
e.xy = this.mousePosition;
|
||||||
e.xy = this.map.events.getMousePosition(e);
|
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
this.callback("down", [e, delta]);
|
this.callback("down", [e, delta]);
|
||||||
} else {
|
} else {
|
||||||
@@ -82,6 +89,10 @@ OpenLayers.Handler.MouseWheel.prototype = OpenLayers.Class.inherit( OpenLayers.H
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mousemove: function (evt) {
|
||||||
|
this.mousePosition = evt.xy;
|
||||||
|
},
|
||||||
|
|
||||||
activate: function (evt) {
|
activate: function (evt) {
|
||||||
OpenLayers.Handler.prototype.activate.apply(this, arguments);
|
OpenLayers.Handler.prototype.activate.apply(this, arguments);
|
||||||
//register mousewheel events specifically on the window and document
|
//register mousewheel events specifically on the window and document
|
||||||
|
|||||||
Reference in New Issue
Block a user