summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Control/PanPanel.html
blob: 978a051f65fb234d67e38956c45ab1c7baef4298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
<head>
  <script src="../OLLoader.js"></script>
  <script type="text/javascript">
    function test_constructor (t) {
        t.plan(2);
        
        // set up
        var control;

        // tests
        control = new OpenLayers.Control.PanPanel({slideFactor: 200});
        t.ok(control.controls[0].slideFactor == 200 &&
             control.controls[1].slideFactor == 200 &&
             control.controls[2].slideFactor == 200 &&
             control.controls[3].slideFactor == 200,
             "ctor sets slideFactor in all Pan controls");
        
        control.destroy();

        control = new OpenLayers.Control.PanPanel({slideRatio: .5});
        t.ok(control.controls[0].slideRatio == .5 &&
             control.controls[1].slideRatio == .5 &&
             control.controls[2].slideRatio == .5 &&
             control.controls[3].slideRatio == .5,
             "ctor sets slideRatio in all Pan controls");
        
        control.destroy();
    }
    
    function test_slide(t) {
        t.plan(2);
        var map = new OpenLayers.Map("map", {
            panMethod: null,
            controls: [
                new OpenLayers.Control.PanPanel(),
                new OpenLayers.Control.PanPanel({slideRatio: .5})
            ],
            layers: [new OpenLayers.Layer(null, {isBaseLayer: true})],
            center: new OpenLayers.LonLat(0, 0),
            zoom: 1
        });
        
        map.controls[0].controls[0].trigger();
        map.controls[0].controls[2].trigger();
        map.pan(-50, 50);
        t.eq(map.getCenter().toShortString(), "0, 0", "correct pan distance with slideFactor");
        
        map.controls[1].controls[0].trigger();
        map.controls[1].controls[2].trigger();
        map.pan(-128, 64);
        t.eq(map.getCenter().toShortString(), "0, 0", "correct pan distance with slideRatio");        

        map.destroy();
    }
  </script>
</head>
<body>
    <div id="map" style="width: 256px; height: 128px;"></div>
</body>
</html>