be very very careful about how we deal with the wheel. only take action when over scrollable items or over the main map. all of this is explained in the ticket and patch it is really late and i dont feel like typing it again. basically, this puppy means that scrolling on controls or in popups will no longer zoom the map unwantedly. that is good. thank you cr5 and IRC for taking such care of me. (r=cr5) (Closes #1382)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@6416 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -66,22 +66,90 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
* e - {Event}
|
* e - {Event}
|
||||||
*/
|
*/
|
||||||
onWheelEvent: function(e){
|
onWheelEvent: function(e){
|
||||||
// first check keyboard modifiers
|
|
||||||
if (!this.checkModifiers(e)) {
|
// make sure we have a map and check keyboard modifiers
|
||||||
|
if (!this.map || !this.checkModifiers(e)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// first determine whether or not the wheeling was inside the map
|
|
||||||
var inMap = false;
|
// Ride up the element's DOM hierarchy to determine if it or any of
|
||||||
|
// its ancestors was:
|
||||||
|
// * specifically marked as scrollable
|
||||||
|
// * one of our layer divs
|
||||||
|
// * the map div
|
||||||
|
//
|
||||||
|
var overScrollableDiv = false;
|
||||||
|
var overLayerDiv = false;
|
||||||
|
var overMapDiv = false;
|
||||||
|
|
||||||
var elem = OpenLayers.Event.element(e);
|
var elem = OpenLayers.Event.element(e);
|
||||||
while(elem != null) {
|
while((elem != null) && !overMapDiv && !overScrollableDiv) {
|
||||||
if (this.map && elem == this.map.div) {
|
|
||||||
inMap = true;
|
if (!overScrollableDiv) {
|
||||||
|
try {
|
||||||
|
if (elem.currentStyle) {
|
||||||
|
overflow = elem.currentStyle["overflow"];
|
||||||
|
} else {
|
||||||
|
var style =
|
||||||
|
document.defaultView.getComputedStyle(elem, null);
|
||||||
|
var overflow = style.getPropertyValue("overflow");
|
||||||
|
}
|
||||||
|
overScrollableDiv = ( overflow &&
|
||||||
|
(overflow == "auto") || (overflow == "scroll") );
|
||||||
|
} catch(err) {
|
||||||
|
//sometimes when scrolling in a popup, this causes
|
||||||
|
// obscure browser error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!overLayerDiv) {
|
||||||
|
for(var i=0; i < this.map.layers.length; i++) {
|
||||||
|
if (elem == this.map.layers[i].div) {
|
||||||
|
overLayerDiv = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
overMapDiv = (elem == this.map.div);
|
||||||
|
|
||||||
elem = elem.parentNode;
|
elem = elem.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inMap) {
|
// Logic below is the following:
|
||||||
|
//
|
||||||
|
// If we are over a scrollable div or not over the map div:
|
||||||
|
// * do nothing (let the browser handle scrolling)
|
||||||
|
//
|
||||||
|
// otherwise
|
||||||
|
//
|
||||||
|
// If we are over the layer div:
|
||||||
|
// * zoom/in out
|
||||||
|
// then
|
||||||
|
// * kill event (so as not to also scroll the page after zooming)
|
||||||
|
//
|
||||||
|
// otherwise
|
||||||
|
//
|
||||||
|
// Kill the event (dont scroll the page if we wheel over the
|
||||||
|
// layerswitcher or the pan/zoom control)
|
||||||
|
//
|
||||||
|
if (!overScrollableDiv && overMapDiv) {
|
||||||
|
if (overLayerDiv) {
|
||||||
|
this.wheelZoom(e);
|
||||||
|
}
|
||||||
|
OpenLayers.Event.stop(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: wheelZoom
|
||||||
|
* Given the wheel event, we carry out the appropriate zooming in or out,
|
||||||
|
* based on the 'wheelDelta' or 'detail' property of the event.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* e - {Event}
|
||||||
|
*/
|
||||||
|
wheelZoom: function(e) {
|
||||||
|
|
||||||
var delta = 0;
|
var delta = 0;
|
||||||
if (!e) {
|
if (!e) {
|
||||||
e = window.event;
|
e = window.event;
|
||||||
@@ -95,8 +163,9 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
delta = -e.detail / 3;
|
delta = -e.detail / 3;
|
||||||
}
|
}
|
||||||
if (delta) {
|
if (delta) {
|
||||||
// add the mouse position to the event because mozilla has a bug
|
// add the mouse position to the event because mozilla has
|
||||||
// with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179)
|
// a bug with clientX and clientY (see
|
||||||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=352179)
|
||||||
// getLonLatFromViewPortPx(e) returns wrong values
|
// getLonLatFromViewPortPx(e) returns wrong values
|
||||||
if (this.mousePosition) {
|
if (this.mousePosition) {
|
||||||
e.xy = this.mousePosition;
|
e.xy = this.mousePosition;
|
||||||
@@ -107,7 +176,9 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
// act as if the mouse was at the center of the map.
|
// act as if the mouse was at the center of the map.
|
||||||
// Note that we can tell we are in the map -- and
|
// Note that we can tell we are in the map -- and
|
||||||
// this.map is ensured to be true above.
|
// this.map is ensured to be true above.
|
||||||
e.xy = this.map.getPixelFromLonLat(this.map.getCenter());
|
e.xy = this.map.getPixelFromLonLat(
|
||||||
|
this.map.getCenter()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
this.callback("down", [e, delta]);
|
this.callback("down", [e, delta]);
|
||||||
@@ -115,10 +186,6 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
this.callback("up", [e, delta]);
|
this.callback("up", [e, delta]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//only wheel the map, not the window
|
|
||||||
OpenLayers.Event.stop(e);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
handler.activate();
|
handler.activate();
|
||||||
var delta = 120;
|
var delta = 120;
|
||||||
if (window.opera && window.opera.version() < 9.2) delta = -delta;
|
if (window.opera && window.opera.version() < 9.2) delta = -delta;
|
||||||
handler.onWheelEvent({'target':map.div, wheelDelta: delta});
|
handler.onWheelEvent({'target':map.layers[0].div, wheelDelta: delta});
|
||||||
t.ok(pass, "evt.xy was set even without a mouse move");
|
t.ok(pass, "evt.xy was set even without a mouse move");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user