OpenLayers OpenLayers

Ticket #575: panzoom.patch

File panzoom.patch, 4.1 kB (added by euzuro, 2 years ago)

only way i know how to do this is using this function simulateClick() and openting the page in a new window. it well may be possible without all this jazz. but this works. in firefox.

  • tests/Control/test_PanZoom.html

    old new  
    2626        map.addControl(control2, new OpenLayers.Pixel(100,100)); 
    2727        t.eq( control2.div.style.top, "100px", "2nd control div is located correctly"); 
    2828    } 
     29 
    2930    function test_03_Control_PanZoom_control_events (t) { 
    30         t.plan( 7 ); 
    31         var evt = {which: 1}; // control expects left-click 
    32         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); 
    3731 
    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" ); 
    4041 
    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" ); 
    4344 
    44         control.buttons[0].onmousedown(evt); 
    45         t.ok( map.getCenter().lat > centerLL.lat, "Pan up works correctly" ); 
     45                    simulateClick(wnd, wnd.control.buttons[2]); 
     46                    t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "Pan right works correctly" ); 
    4647 
    47         control.buttons[1].onmousedown(evt); 
    48         t.ok( map.getCenter().lon < centerLL.lon, "Pan left works correctly" ); 
     48                    simulateClick(wnd, wnd.control.buttons[3]); 
     49                    t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "Pan down works correctly" ); 
    4950 
    50         control.buttons[2].onmousedown(evt); 
    51         t.ok( map.getCenter().lon == centerLL.lon, "Pan right works correctly" ); 
     51                    simulateClick(wnd, wnd.control.buttons[4]); 
     52                    t.eq( wnd.mapper.getZoom(), 6, "zoomin works correctly" ); 
    5253 
    53         control.buttons[3].onmousedown(evt); 
    54         t.ok( map.getCenter().lat == centerLL.lat, "Pan down works correctly" ); 
     54                    simulateClick(wnd, wnd.control.buttons[6]); 
     55                    t.eq( wnd.mapper.getZoom(), 5, "zoomout works correctly" ); 
    5556 
    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    } 
    5863 
    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    } 
    6169 
    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); 
    6583    } 
     84         
    6685  // --> 
    6786  </script> 
    6887</head> 
    69 <body
     88<body onload="loader()"
    7089    <div id="map" style="width: 1024px; height: 512px;"/> 
    7190</body> 
    7291</html>