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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var map;
function test_Control_PanZoomBar_constructor (t) {
t.plan( 4 );
control = new OpenLayers.Control.PanZoomBar({position: new OpenLayers.Pixel(100,100)});
t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" );
t.eq( control.displayClass, "olControlPanZoomBar", "displayClass is correct" );
t.eq( control.position.x, 100, "PanZoom X Set correctly.");
t.eq( control.position.y, 100, "PanZoom y Set correctly.");
}
function test_Control_PanZoomBar_addControl (t) {
t.plan( 8 );
map = new OpenLayers.Map('map', {controls:[]});
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
control = new OpenLayers.Control.PanZoomBar();
t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" );
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" );
map.addControl(control);
t.ok( control.map === map, "Control.map is set to the map object" );
t.ok( map.controls[0] === control, "map.controls contains control" );
t.eq( parseInt(control.div.style.zIndex), 1001, "Control div zIndexed properly" );
t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), 1001, "Viewport div contains control div" );
t.eq( control.div.style.top, "4px", "Control div top located correctly by default");
var control2 = new OpenLayers.Control.PanZoomBar();
map.addControl(control2, new OpenLayers.Pixel(100,100));
t.eq( control2.div.style.top, "100px", "2nd control div is located correctly");
}
function test_draw(t) {
t.plan(3);
map = new OpenLayers.Map('map', {controls:[]});
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
map.zoomToMaxExtent();
control = new OpenLayers.Control.PanZoomBar();
map.addControl(control);
t.eq(control.zoombarDiv.style.height, '176px', "Bar's height is correct.");
map.baseLayer.wrapDateLine = true;
control.redraw();
t.eq(control.zoombarDiv.style.height, '154px', "Bar's height is correct after minZoom restriction.");
map.div.style.width = "512px";
map.updateSize();
t.eq(control.zoombarDiv.style.height, '165px', "Bar's height is correct after resize and minZoom restriction.");
map.div.style.width = "1024px";
map.destroy();
}
function test_Control_PanZoomBar_clearDiv(t) {
t.plan(2);
map = new OpenLayers.Map('map', {controls:[]});
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
control = new OpenLayers.Control.PanZoomBar();
map.addControl(control);
control.removeButtons();
var div = control.div;
map.destroy();
t.eq(div.childNodes.length, 0, "control's div cleared.");
t.eq(control.zoombarDiv, null, "zoombar div nullified.")
}
function test_Control_PanZoomBar_onButtonClick (t) {
t.plan(2);
map = new OpenLayers.Map('map', {controls:[], zoomMethod: null});
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
control = new OpenLayers.Control.PanZoomBar();
map.addControl(control);
control.onButtonClick({'buttonXY': {'x': 0, 'y': 50}, buttonElement: control.zoombarDiv});
t.eq(map.zoom, 11, "zoom is correct on standard map");
map.fractionalZoom = true;
control.onButtonClick({'buttonXY': {'x': 0, 'y': 49}, buttonElement: control.zoombarDiv});
t.eq(map.zoom.toFixed(3), '10.545', "zoom is correct on fractional zoom map");
}
function test_Control_PanZoomBar_forceFixedZoomLevel_onButtonClick(t){
t.plan(1);
map = new OpenLayers.Map('map', {
controls: [],
fractionalZoom: true,
zoomMethod: null
});
var layer = new OpenLayers.Layer.WMS("Test Layer", "http://octo.metacarta.com/cgi-bin/mapserv?", {
map: "/mapdata/vmap_wms.map",
layers: "basic"
});
map.addLayer(layer);
control = new OpenLayers.Control.PanZoomBar({
forceFixedZoomLevel: true
});
map.addControl(control);
control.onButtonClick({
'buttonXY': {
'x': 0,
'y': 49
},
buttonElement: control.zoombarDiv
});
t.eq(map.zoom, 11, "forceFixedZoomLevel makes sure that after a div click only fixed zoom levels are used even if the map has fractionalZoom");
}
function test_Control_PanZoomBar_forceFixedZoomLevel_zoomBarUp (t) {
var numRandomDrags = 25;
// plan one static recorded test and two for every random drag
t.plan(1 + (numRandomDrags * 2));
var map = new OpenLayers.Map('map', {
controls: [],
fractionalZoom: true,
zoomMethod: null
});
var layer = new OpenLayers.Layer.WMS("Test Layer", "http://octo.metacarta.com/cgi-bin/mapserv?", {
map: "/mapdata/vmap_wms.map",
layers: "basic"
});
map.addLayer(layer);
// zoom to a fractional ZoomLevel initially:
map.setCenter(new OpenLayers.LonLat(0, 0), 9.545);
control = new OpenLayers.Control.PanZoomBar({
forceFixedZoomLevel: true
});
map.addControl(control);
// The y values come from manually recording real values in an example
var evt = {
'xy': {
'x': 0,
'y': -10.633
},
which: 1
};
control.zoomStart = {
'x': 0,
'y': 5.366
};
control.mouseDragStart = {
'x': 0,
'y': -10.633
};
control.deltaY = control.zoomStart.y - evt.xy.y
control.zoomBarUp(evt);
t.eq(map.zoom, 11, "forceFixedZoomLevel makes sure that after dragging of the handle only fixed zoom levels are used even if the map has fractionalZoom");
// randomly drag the handle around
// we should never get a zoom < 0 or a non-integer zoom, regardless of
// captured random values for start and end of the drag.
for (var i = 0; i < numRandomDrags; i++) {
var randStartY = Math.random() * 10 * ((i % 2 === 0) ? -1 : 1);
var randStopY = Math.random() * 160 * ((i % 2 === 1) ? -1 : 1);
var evt = {
'xy': {
'x': 0,
'y': randStopY
},
which: 1
};
control.zoomStart = {
'x': 0,
'y': randStartY
};
control.mouseDragStart = {
'x': 0,
'y': randStopY
};
control.deltaY = control.zoomStart.y - evt.xy.y
control.zoomBarUp(evt);
t.eq(Math.floor(map.zoom), Math.ceil(map.zoom), 'Only integer zooms after random handle drag with forceFixedZoomLevel=true and fractionalZoom=true (current zoom was ' + map.zoom + ')');
t.ok(map.zoom >= 0, 'map.zoom is never < 0 after random handle drag with forceFixedZoomLevel=true and fractionalZoom=true');
}
}
function test_Control_PanZoomBar_shows (t) {
t.plan(22);
var control, map;
control = new OpenLayers.Control.PanZoomBar({panIcons: true, zoomWorldIcon: false});
map = new OpenLayers.Map('map', {controls: [control]});
t.eq(control.buttons.length, 6, "(a) pan, no world - expected number of buttons");
t.ok(control.buttons[0].id.match("_panup$"), "(a) pan, no world - pan up");
t.ok(control.buttons[1].id.match("_panleft$"), "(a) pan, no world - pan left");
t.ok(control.buttons[2].id.match("_panright$"), "(a) pan, no world - pan right");
t.ok(control.buttons[3].id.match("_pandown$"), "(a) pan, no world - pan down");
t.ok(control.buttons[4].id.match("_zoomin$"), "(a) pan, no world - zoom in");
t.ok(control.buttons[5].id.match("_zoomout$"), "(a) pan, no world - zoom out");
map.destroy();
control = new OpenLayers.Control.PanZoomBar({panIcons: true, zoomWorldIcon: true});
map = new OpenLayers.Map('map', {controls:[control]});
t.eq(control.buttons.length, 7, "(b) pan, world - expected number of buttons");
t.ok(control.buttons[0].id.match("_panup$"), "(b) pan, world - pan up");
t.ok(control.buttons[1].id.match("_panleft$"), "(b) pan, world - pan left");
t.ok(control.buttons[2].id.match("_zoomworld$"), "(b) pan, world - zoom world");
t.ok(control.buttons[3].id.match("_panright$"), "(b) pan, world - pan right");
t.ok(control.buttons[4].id.match("_pandown$"), "(b) pan, world - pan down");
t.ok(control.buttons[5].id.match("_zoomin$"), "(b) pan, world - zoom in");
t.ok(control.buttons[6].id.match("_zoomout$"), "(b) pan, world - zoom out");
map.destroy();
control = new OpenLayers.Control.PanZoomBar({panIcons: false, zoomWorldIcon: false});
map = new OpenLayers.Map('map', {controls:[control]});
t.eq(control.buttons.length, 2, "(c) no pan, no world - expected number of buttons");
t.ok(control.buttons[0].id.match("_zoomin$"), "(c) no pan, no world - zoom in");
t.ok(control.buttons[1].id.match("_zoomout$"), "(c) no pan, no world - zoom out");
map.destroy();
control = new OpenLayers.Control.PanZoomBar({panIcons: false, zoomWorldIcon: true});
map = new OpenLayers.Map('map', {controls:[control]});
t.eq(control.buttons.length, 3, "(d) no pan, world - expected number of buttons");
t.ok(control.buttons[0].id.match("_zoomin$"), "(d) no pan, world - zoom in");
t.ok(control.buttons[1].id.match("_zoomout$"), "(d) no pan, world - zoom out");
t.ok(control.buttons[2].id.match("_zoomworld$"), "(d) no pan, world - zoom world");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>
|