~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/Control/NavigationHistory.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
  <script src="../../lib/OpenLayers.js"></script>
 
4
  <script type="text/javascript">
 
5
 
 
6
    function test_initialize(t) {
 
7
        t.plan(4);
 
8
        control = new OpenLayers.Control.NavigationHistory();
 
9
        t.ok(control instanceof OpenLayers.Control.NavigationHistory,
 
10
             "constructor returns correct instance");
 
11
        t.eq(control.displayClass, "olControlNavigationHistory",
 
12
             "displayClass is correct");
 
13
        t.ok(control.next instanceof OpenLayers.Control.Button,
 
14
             "constructor creates next control");
 
15
        t.ok(control.previous instanceof OpenLayers.Control.Button,
 
16
             "constructor creates previous control");
 
17
    }
 
18
 
 
19
    function test_destroy(t) {
 
20
        t.plan(2);
 
21
        control = new OpenLayers.Control.NavigationHistory();
 
22
        control.next.destroy = function() {
 
23
            t.ok(true, "destroy calls next.destroy");
 
24
        }
 
25
        control.previous.destroy = function() {
 
26
            t.ok(true, "destroy calls previous.destroy");
 
27
        }
 
28
        control.destroy();
 
29
    }
 
30
    
 
31
    function test_previous(t) {
 
32
        var numStates = 10;
 
33
        
 
34
        t.plan(
 
35
            numStates * 3 // for lon, lat, zoom
 
36
            + 3 // for confirming that previous with empty stack works
 
37
        );       
 
38
 
 
39
        var history = new Array(numStates);
 
40
        for(var i=0; i<numStates; ++i) {
 
41
            history[i] = {
 
42
                center: new OpenLayers.LonLat(
 
43
                    (i * 360 / numStates) - 180, (i * 180 / numStates) - 90
 
44
                ),
 
45
                zoom: i
 
46
            };
 
47
        }
 
48
        
 
49
        var map = new OpenLayers.Map("map");
 
50
        var layer = new OpenLayers.Layer(
 
51
            "test", {isBaseLayer: true}
 
52
        );
 
53
        map.addLayer(layer);
 
54
        var control = new OpenLayers.Control.NavigationHistory();
 
55
        map.addControl(control);
 
56
        
 
57
        // set previous states
 
58
        for(i=0; i<numStates; ++i) {
 
59
            map.setCenter(history[i].center, history[i].zoom);
 
60
        }
 
61
        // test previous states
 
62
        for(i=numStates-1; i>=0; --i) {
 
63
            t.eq(map.getCenter().lon, history[i].center.lon, "(step " + i + ") lon correct");
 
64
            t.eq(map.getCenter().lat, history[i].center.lat, "(step " + i + ") lat correct");
 
65
            t.eq(map.getZoom(), history[i].zoom, "(step " + i + ") zoom correct");
 
66
            control.previous.trigger();
 
67
        }
 
68
        // test previous with empty stack
 
69
        t.eq(map.getCenter().lon, history[0].center.lon, "(step 0 again) lon correct");
 
70
        t.eq(map.getCenter().lat, history[0].center.lat, "(step 0 again) lat correct");
 
71
        t.eq(map.getZoom(), history[0].zoom, "(step 0 again) zoom correct");
 
72
    }
 
73
 
 
74
    function test_next(t) {
 
75
        var numStates = 10;
 
76
        
 
77
        t.plan(
 
78
            numStates * 3 // for lon, lat, zoom
 
79
            + 3 // for confirming that next with empty stack works
 
80
        );
 
81
 
 
82
        var history = new Array(numStates);
 
83
        for(var i=0; i<numStates; ++i) {
 
84
            history[i] = {
 
85
                center: new OpenLayers.LonLat(
 
86
                    (i * 360 / numStates) - 180, (i * 180 / numStates) - 90
 
87
                ),
 
88
                zoom: i
 
89
            };
 
90
        }
 
91
        
 
92
        var map = new OpenLayers.Map("map");
 
93
        var layer = new OpenLayers.Layer(
 
94
            "test", {isBaseLayer: true}
 
95
        );
 
96
        map.addLayer(layer);
 
97
        var control = new OpenLayers.Control.NavigationHistory();
 
98
        map.addControl(control);
 
99
        
 
100
        // set previous states
 
101
        for(i=0; i<numStates; ++i) {
 
102
            map.setCenter(history[i].center, history[i].zoom);
 
103
        }
 
104
        // set next states
 
105
        for(i=numStates-1; i>=0; --i) {
 
106
            control.previous.trigger();
 
107
        }
 
108
        // test next states
 
109
        for(i=0; i<numStates; ++i) {
 
110
            t.eq(map.getCenter().lon, history[i].center.lon, "(step " + i + ") lon correct");
 
111
            t.eq(map.getCenter().lat, history[i].center.lat, "(step " + i + ") lat correct");
 
112
            t.eq(map.getZoom(), history[i].zoom, "(step " + i + ") zoom correct");
 
113
            control.next.trigger();
 
114
        }
 
115
        // test next with empty stack
 
116
        t.eq(map.getCenter().lon, history[numStates-1].center.lon, "(step " + (numStates-1) + " again) lon correct");
 
117
        t.eq(map.getCenter().lat, history[numStates-1].center.lat, "(step " + (numStates-1) + " again) lat correct");
 
118
        t.eq(map.getZoom(), history[numStates-1].zoom, "(step " + (numStates-1) + " again) zoom correct");
 
119
    }
 
120
    
 
121
    function test_limit(t) {
 
122
        var numStates = 10;
 
123
        var limit = 3;
 
124
        
 
125
        t.plan(
 
126
            numStates * 6 // for previous & next lon, lat, zoom
 
127
        );
 
128
 
 
129
        var history = new Array(numStates);
 
130
        for(var i=0; i<numStates; ++i) {
 
131
            history[i] = {
 
132
                center: new OpenLayers.LonLat(
 
133
                    (i * 360 / numStates) - 180, (i * 180 / numStates) - 90
 
134
                ),
 
135
                zoom: i
 
136
            };
 
137
        }
 
138
        
 
139
        var map = new OpenLayers.Map("map");
 
140
        var layer = new OpenLayers.Layer(
 
141
            "test", {isBaseLayer: true}
 
142
        );
 
143
        map.addLayer(layer);
 
144
        var control = new OpenLayers.Control.NavigationHistory({limit: limit});
 
145
        map.addControl(control);
 
146
        
 
147
        // set previous states
 
148
        for(i=0; i<numStates; ++i) {
 
149
            map.setCenter(history[i].center, history[i].zoom);
 
150
        }
 
151
        // test previous states (only up to limit should work)
 
152
        var state;
 
153
        for(i=numStates-1; i>=0; --i) {
 
154
            state = Math.max(i, numStates - limit - 1);
 
155
            t.eq(map.getCenter().lon, history[state].center.lon, "(previous step " + i + ") lon correct: state " + state);
 
156
            t.eq(map.getCenter().lat, history[state].center.lat, "(previous step " + i + ") lat correct: state " + state);
 
157
            t.eq(map.getZoom(), history[state].zoom, "(previous step " + i + ") zoom correct: state " + state);
 
158
            control.previous.trigger();
 
159
        }
 
160
        // test next states
 
161
        for(i=0; i<numStates; ++i) {
 
162
            state = Math.min(numStates - 1, numStates - limit - 1 + i);
 
163
            t.eq(map.getCenter().lon, history[state].center.lon, "(next step " + i + ") lon correct: state " + state);
 
164
            t.eq(map.getCenter().lat, history[state].center.lat, "(next step " + i + ") lat correct: state " + state);
 
165
            t.eq(map.getZoom(), history[state].zoom, "(next step " + i + ") zoom correct: state " + state);
 
166
            control.next.trigger();
 
167
        }
 
168
        
 
169
    }
 
170
 
 
171
  </script>
 
172
</head>
 
173
<body>
 
174
    <div id="map" style="width: 100px; height: 100px;"/>
 
175
</body>
 
176
</html>