Ticket #575: panzoom.patch
| File panzoom.patch, 4.1 kB (added by euzuro, 2 years ago) |
|---|
-
tests/Control/test_PanZoom.html
old new 26 26 map.addControl(control2, new OpenLayers.Pixel(100,100)); 27 27 t.eq( control2.div.style.top, "100px", "2nd control div is located correctly"); 28 28 } 29 29 30 function test_03_Control_PanZoom_control_events (t) { 30 t.plan( 7 );31 var evt = {which: 1}; // control expects left-click32 map = new OpenLayers.Map('map');33 var layer = new OpenLayers.Layer.WMS("Test Layer",34 "http://octo.metacarta.com/cgi-bin/mapserv?",35 {map: "/mapdata/vmap_wms.map", layers: "basic"});36 map.addLayer(layer);37 31 38 control = new OpenLayers.Control.PanZoom(); 39 map.addControl(control, new OpenLayers.Pixel(20,20)); 32 if ( !window.document.createEvent ) { 33 //ie can't simulate mouseclicks 34 t.plan(0) 35 } else { 36 t.plan( 7 ); 37 t.open_window( "Control/test_PanZoom.html", function( wnd ) { 38 t.delay_call( 3, function() { 39 simulateClick(wnd, wnd.control.buttons[0]); 40 t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "Pan up works correctly" ); 40 41 41 var centerLL = new OpenLayers.LonLat(0,0);42 map.setCenter(centerLL, 5);42 simulateClick(wnd, wnd.control.buttons[1]); 43 t.ok( wnd.mapper.getCenter().lon < wnd.centerLL.lon, "Pan left works correctly" ); 43 44 44 control.buttons[0].onmousedown(evt);45 t.ok( map.getCenter().lat > centerLL.lat, "Pan upworks correctly" );45 simulateClick(wnd, wnd.control.buttons[2]); 46 t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "Pan right works correctly" ); 46 47 47 control.buttons[1].onmousedown(evt);48 t.ok( map.getCenter().lon < centerLL.lon, "Pan leftworks correctly" );48 simulateClick(wnd, wnd.control.buttons[3]); 49 t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "Pan down works correctly" ); 49 50 50 control.buttons[2].onmousedown(evt);51 t.ok( map.getCenter().lon == centerLL.lon, "Pan rightworks correctly" );51 simulateClick(wnd, wnd.control.buttons[4]); 52 t.eq( wnd.mapper.getZoom(), 6, "zoomin works correctly" ); 52 53 53 control.buttons[3].onmousedown(evt);54 t.ok( map.getCenter().lat == centerLL.lat, "Pan downworks correctly" );54 simulateClick(wnd, wnd.control.buttons[6]); 55 t.eq( wnd.mapper.getZoom(), 5, "zoomout works correctly" ); 55 56 56 control.buttons[4].onmousedown(evt); 57 t.eq( map.getZoom(), 6, "zoomin works correctly" ); 57 simulateClick(wnd, wnd.control.buttons[5]); 58 t.eq( wnd.mapper.getZoom(), 2, "zoomworld works correctly" ); 59 }); 60 }); 61 } 62 } 58 63 59 control.buttons[6].onmousedown(evt); 60 t.eq( map.getZoom(), 5, "zoomout works correctly" ); 64 function simulateClick(wnd, elem) { 65 var evt = wnd.document.createEvent("MouseEvents"); 66 evt.initMouseEvent("mousedown", true, true, wnd, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 67 var canceled = !elem.dispatchEvent(evt); 68 } 61 69 62 control.buttons[5].onmousedown(evt); 63 t.eq( map.getZoom(), 2, "zoomworld works correctly" ); 64 70 function loader() { 71 control = new OpenLayers.Control.PanZoom(); 72 73 mapper = new OpenLayers.Map('map', { controls: [control]}); 74 75 76 var layer = new OpenLayers.Layer.WMS("Test Layer", 77 "http://octo.metacarta.com/cgi-bin/mapserv?", 78 {map: "/mapdata/vmap_wms.map", layers: "basic"}); 79 mapper.addLayer(layer); 80 81 centerLL = new OpenLayers.LonLat(0,0); 82 mapper.setCenter(centerLL, 5); 65 83 } 84 66 85 // --> 67 86 </script> 68 87 </head> 69 <body >88 <body onload="loader()"> 70 89 <div id="map" style="width: 1024px; height: 512px;"/> 71 90 </body> 72 91 </html>
