From ab40f522c971807e45e973ea9b336b7b5b3231e2 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sat, 25 Aug 2007 07:46:52 +0000 Subject: [PATCH] "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 --- lib/OpenLayers/Handler/MouseWheel.js | 12 ++- tests/Handler/test_MouseWheel.html | 122 +++++++++++++++++++++++++++ tests/list-tests.html | 1 + 3 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 tests/Handler/test_MouseWheel.html diff --git a/lib/OpenLayers/Handler/MouseWheel.js b/lib/OpenLayers/Handler/MouseWheel.js index fb11e9a194..5d5dac3b3f 100644 --- a/lib/OpenLayers/Handler/MouseWheel.js +++ b/lib/OpenLayers/Handler/MouseWheel.js @@ -94,7 +94,17 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, { // 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 (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) { this.callback("down", [e, delta]); } else { diff --git a/tests/Handler/test_MouseWheel.html b/tests/Handler/test_MouseWheel.html new file mode 100644 index 0000000000..b80e3bb51e --- /dev/null +++ b/tests/Handler/test_MouseWheel.html @@ -0,0 +1,122 @@ + + + + + + +
+ + diff --git a/tests/list-tests.html b/tests/list-tests.html index 4e5e3983fe..7889ebb26e 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -72,6 +72,7 @@
  • Control/test_Permalink.html
  • Control/test_Scale.html
  • test_Handler.html
  • +
  • Handler/test_MouseWheel.html
  • Handler/test_Drag.html
  • Handler/test_Point.html
  • Handler/test_Path.html