diff --git a/lib/OpenLayers/Control/PanZoom.js b/lib/OpenLayers/Control/PanZoom.js index 5762a9eee4..2af98474e1 100644 --- a/lib/OpenLayers/Control/PanZoom.js +++ b/lib/OpenLayers/Control/PanZoom.js @@ -104,6 +104,8 @@ OpenLayers.Control.PanZoom.prototype = this.doubleClick.bindAsEventListener(btn)); OpenLayers.Event.observe(btn, "dblclick", this.doubleClick.bindAsEventListener(btn)); + OpenLayers.Event.observe(btn, "click", + this.doubleClick.bindAsEventListener(btn)); btn.action = id; btn.map = this.map; btn.slideFactor = this.slideFactor; diff --git a/tests/Control/test_PanZoom.html b/tests/Control/test_PanZoom.html index faf1e92d68..efd1b9b7e6 100644 --- a/tests/Control/test_PanZoom.html +++ b/tests/Control/test_PanZoom.html @@ -36,29 +36,84 @@ //ie can't simulate mouseclicks t.plan(0) } else { - t.plan( 7 ); + t.plan(35); t.open_window( "Control/test_PanZoom.html", function( wnd ) { t.delay_call( 3, function() { - simulateClick(wnd, wnd.control.buttons[0]); + var flag; + function setFlag(evt) { + flag[evt.type] = true; + } + function resetFlags() { + flag = { + mousedown: false, + mouseup: false, + click: false, + dblclick: false + }; + } + resetFlags(); + + wnd.mapper.events.register("mousedown", mapper, setFlag); + wnd.mapper.events.register("mouseup", mapper, setFlag); + wnd.mapper.events.register("click", mapper, setFlag); + wnd.mapper.events.register("dblclick", mapper, setFlag); + + simulateClick(wnd, wnd.control.buttons[0]); t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "Pan up works correctly" ); + t.ok(!flag.mousedown, "mousedown does not get to the map"); + t.ok(!flag.mouseup, "mouseup does not get to the map"); + t.ok(!flag.click, "click does not get to the map"); + t.ok(!flag.dblclick, "dblclick does not get to the map"); + resetFlags(); simulateClick(wnd, wnd.control.buttons[1]); t.ok( wnd.mapper.getCenter().lon < wnd.centerLL.lon, "Pan left works correctly" ); + t.ok(!flag.mousedown, "mousedown does not get to the map"); + t.ok(!flag.mouseup, "mouseup does not get to the map"); + t.ok(!flag.click, "click does not get to the map"); + t.ok(!flag.dblclick, "dblclick does not get to the map"); + resetFlags(); simulateClick(wnd, wnd.control.buttons[2]); t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "Pan right works correctly" ); + t.ok(!flag.mousedown, "mousedown does not get to the map"); + t.ok(!flag.mouseup, "mouseup does not get to the map"); + t.ok(!flag.click, "click does not get to the map"); + t.ok(!flag.dblclick, "dblclick does not get to the map"); + resetFlags(); simulateClick(wnd, wnd.control.buttons[3]); t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "Pan down works correctly" ); + t.ok(!flag.mousedown, "mousedown does not get to the map"); + t.ok(!flag.mouseup, "mouseup does not get to the map"); + t.ok(!flag.click, "click does not get to the map"); + t.ok(!flag.dblclick, "dblclick does not get to the map"); + resetFlags(); simulateClick(wnd, wnd.control.buttons[4]); t.eq( wnd.mapper.getZoom(), 6, "zoomin works correctly" ); + t.ok(!flag.mousedown, "mousedown does not get to the map"); + t.ok(!flag.mouseup, "mouseup does not get to the map"); + t.ok(!flag.click, "click does not get to the map"); + t.ok(!flag.dblclick, "dblclick does not get to the map"); + resetFlags(); simulateClick(wnd, wnd.control.buttons[6]); t.eq( wnd.mapper.getZoom(), 5, "zoomout works correctly" ); + t.ok(!flag.mousedown, "mousedown does not get to the map"); + t.ok(!flag.mouseup, "mouseup does not get to the map"); + t.ok(!flag.click, "click does not get to the map"); + t.ok(!flag.dblclick, "dblclick does not get to the map"); + resetFlags(); simulateClick(wnd, wnd.control.buttons[5]); t.eq( wnd.mapper.getZoom(), 2, "zoomworld works correctly" ); + t.ok(!flag.mousedown, "mousedown does not get to the map"); + t.ok(!flag.mouseup, "mouseup does not get to the map"); + t.ok(!flag.click, "click does not get to the map"); + t.ok(!flag.dblclick, "dblclick does not get to the map"); + resetFlags(); + }); }); } @@ -67,7 +122,19 @@ function simulateClick(wnd, elem) { var evt = wnd.document.createEvent("MouseEvents"); evt.initMouseEvent("mousedown", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null); - var canceled = !elem.dispatchEvent(evt); + elem.dispatchEvent(evt); + + evt = wnd.document.createEvent("MouseEvents"); + evt.initMouseEvent("mouseup", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + elem.dispatchEvent(evt); + + evt = wnd.document.createEvent("MouseEvents"); + evt.initMouseEvent("click", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + elem.dispatchEvent(evt); + + evt = wnd.document.createEvent("MouseEvents"); + evt.initMouseEvent("dblclick", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + elem.dispatchEvent(evt); } function loader() {