"JS error after using mousewheel without having moved the mouse before."
Update MouseWheel handler to use center of map if no mousemovement has been seen yet. (Closes #882) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4042 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -94,7 +94,17 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
// 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
|
||||||
e.xy = this.mousePosition;
|
if (this.mousePosition) {
|
||||||
|
e.xy = this.mousePosition;
|
||||||
|
}
|
||||||
|
if (!e.xy) {
|
||||||
|
// If the mouse hasn't moved over the map yet, then
|
||||||
|
// we don't have a mouse position (in FF), so we just
|
||||||
|
// act as if the mouse was at the center of the map.
|
||||||
|
// Note that we can tell we are in the map -- and
|
||||||
|
// this.map is ensured to be true above.
|
||||||
|
e.xy = this.map.getPixelFromLonLat(this.map.getCenter());
|
||||||
|
}
|
||||||
if (delta < 0) {
|
if (delta < 0) {
|
||||||
this.callback("down", [e, delta]);
|
this.callback("down", [e, delta]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript"><!--
|
||||||
|
function test_Handler_MouseWheel_constructor(t) {
|
||||||
|
t.plan(3);
|
||||||
|
var control = new OpenLayers.Control();
|
||||||
|
control.id = Math.random();
|
||||||
|
var callbacks = {foo: "bar"};
|
||||||
|
var options = {bar: "foo"};
|
||||||
|
|
||||||
|
var oldInit = OpenLayers.Handler.prototype.initialize;
|
||||||
|
|
||||||
|
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
|
||||||
|
t.eq(con.id, control.id,
|
||||||
|
"constructor calls parent with the correct control");
|
||||||
|
t.eq(call, callbacks,
|
||||||
|
"constructor calls parent with the correct callbacks");
|
||||||
|
t.eq(opt, options,
|
||||||
|
"constructor calls parent with the correct options");
|
||||||
|
}
|
||||||
|
var handler = new OpenLayers.Handler.MouseWheel(control, callbacks, options);
|
||||||
|
|
||||||
|
OpenLayers.Handler.prototype.initialize = oldInit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Handler_MouseWheel_activate(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var control = new OpenLayers.Control();
|
||||||
|
map.addControl(control);
|
||||||
|
var handler = new OpenLayers.Handler.MouseWheel(control);
|
||||||
|
handler.active = true;
|
||||||
|
var activated = handler.activate();
|
||||||
|
t.ok(!activated,
|
||||||
|
"activate returns false if the handler was already active");
|
||||||
|
handler.active = false;
|
||||||
|
activated = handler.activate();
|
||||||
|
t.ok(activated,
|
||||||
|
"activate returns true if the handler was not already active");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Handler_MouseWheel_mousePosition(t) {
|
||||||
|
t.plan(1);
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
map.addLayer(new OpenLayers.Layer.WMS("","",{}));
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
var control = new OpenLayers.Control();
|
||||||
|
map.addControl(control);
|
||||||
|
var pass = false;
|
||||||
|
var handler = new OpenLayers.Handler.MouseWheel(control, {'up':
|
||||||
|
function (evt) {
|
||||||
|
if (evt.xy) { pass = true; }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
handler.setMap(map);
|
||||||
|
handler.activate();
|
||||||
|
handler.onWheelEvent({'target':map.div, wheelDelta: 120});
|
||||||
|
t.ok(pass, "evt.xy was set even without a mouse move");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Handler_MouseWheel_events(t) {
|
||||||
|
t.plan(5);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var control = new OpenLayers.Control();
|
||||||
|
map.addControl(control);
|
||||||
|
var handler = new OpenLayers.Handler.MouseWheel(control);
|
||||||
|
|
||||||
|
// list below events that should be handled (events) and those
|
||||||
|
// that should not be handled (nonevents) by the handler
|
||||||
|
var events = ["mousemove"];
|
||||||
|
var nonevents = ["dblclick", "resize", "focus", "blur"];
|
||||||
|
map.events.registerPriority = function(type, obj, func) {
|
||||||
|
t.eq(OpenLayers.Util.indexOf(nonevents, type), -1,
|
||||||
|
"registered method is not one of the events " +
|
||||||
|
"that should not be handled");
|
||||||
|
t.ok(OpenLayers.Util.indexOf(events, type) > -1,
|
||||||
|
"activate calls registerPriority with browser event: " + type);
|
||||||
|
t.eq(typeof func, "function",
|
||||||
|
"activate calls registerPriority with a function");
|
||||||
|
t.eq(func(), type,
|
||||||
|
"activate calls registerPriority with the correct method");
|
||||||
|
t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.MouseWheel",
|
||||||
|
"activate calls registerPriority with the handler");
|
||||||
|
}
|
||||||
|
|
||||||
|
// set browser event like properties on the handler
|
||||||
|
for(var i=0; i<events.length; ++i) {
|
||||||
|
setMethod(events[i]);
|
||||||
|
}
|
||||||
|
function setMethod(key) {
|
||||||
|
handler[key] = function() {return key};
|
||||||
|
}
|
||||||
|
|
||||||
|
var activated = handler.activate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Handler_MouseWheel_deactivate(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var control = new OpenLayers.Control();
|
||||||
|
map.addControl(control);
|
||||||
|
var handler = new OpenLayers.Handler.MouseWheel(control);
|
||||||
|
handler.active = false;
|
||||||
|
var deactivated = handler.deactivate();
|
||||||
|
t.ok(!deactivated,
|
||||||
|
"deactivate returns false if the handler was not already active");
|
||||||
|
handler.active = true;
|
||||||
|
deactivated = handler.deactivate();
|
||||||
|
t.ok(deactivated,
|
||||||
|
"deactivate returns true if the handler was active already");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -->
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="map" style="width: 300px; height: 150px;"/>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -72,6 +72,7 @@
|
|||||||
<li>Control/test_Permalink.html</li>
|
<li>Control/test_Permalink.html</li>
|
||||||
<li>Control/test_Scale.html</li>
|
<li>Control/test_Scale.html</li>
|
||||||
<li>test_Handler.html</li>
|
<li>test_Handler.html</li>
|
||||||
|
<li>Handler/test_MouseWheel.html</li>
|
||||||
<li>Handler/test_Drag.html</li>
|
<li>Handler/test_Drag.html</li>
|
||||||
<li>Handler/test_Point.html</li>
|
<li>Handler/test_Point.html</li>
|
||||||
<li>Handler/test_Path.html</li>
|
<li>Handler/test_Path.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user