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
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
function test_Control_Navigation_constructor (t) {
t.plan( 3 );
var temp = OpenLayers.Control.prototype.initialize;
OpenLayers.Control.prototype.initialize = function() {
t.ok(true, "OpenLayers.Control's constructor called");
};
var control = new OpenLayers.Control.Navigation();
t.ok( control instanceof OpenLayers.Control.Navigation, "new OpenLayers.Control returns object" );
t.ok( !control.handleRightClicks, "'handleRightClicks' property is disabled by default");
OpenLayers.Control.prototype.initialize = temp;
}
function test_draw(t) {
t.plan(5);
var map = new OpenLayers.Map({div: 'map', controls: []});
var control = new OpenLayers.Control.Navigation();
map.addControl(control);
t.ok(control.handlers.click instanceof OpenLayers.Handler.Click,
"click handler set in instance");
t.ok(control.dragPan instanceof OpenLayers.Control.DragPan,
"drag pan control set in instance");
t.ok(control.zoomBox instanceof OpenLayers.Control.ZoomBox,
"zoom box control set in instance");
t.ok(control.handlers.wheel instanceof OpenLayers.Handler.MouseWheel,
"mousewheel handler set in instance");
t.ok(control.pinchZoom instanceof OpenLayers.Control.PinchZoom,
"pinch zoom control set in instance");
map.destroy();
}
function test_Control_Navigation_destroy (t) {
t.plan(12);
var temp = OpenLayers.Control.prototype.destroy;
OpenLayers.Control.prototype.destroy = function() {
t.ok(true, "OpenLayers.Control's destroy called");
temp.call(this);
};
var control = {
events: {
destroy: function() {
t.ok(true, "events destroyed");
}
},
'deactivate': function() {
t.ok(true, "navigation control deactivated before being destroyed");
},
'dragPan': {
'destroy': function() {
t.ok(true, "dragPan destroyed");
}
},
'zoomBox': {
'destroy': function() {
t.ok(true, "zoomBox destroyed");
}
},
'pinchZoom': {
'destroy': function() {
t.ok(true, "pinchZoom destroyed");
}
},
handlers: {
'wheel': {
'destroy': function() {
t.ok(true, "wheelHandler destroyed");
}
},
'click': {
'destroy': function() {
t.ok(true, "clickHandler destroyed");
}
}
}
};
//this will also trigger one test by calling OpenLayers.Control's destroy
// and three more for the destruction of dragPan, zoomBox, and wheelHandler
OpenLayers.Control.Navigation.prototype.destroy.apply(control, []);
t.eq(control.dragPan, null, "'dragPan' set to null");
t.eq(control.zoomBox, null, "'zoomBox' set to null");
t.eq(control.pinchZoom, null, "'pinchZoom' set to null");
t.eq(control.handlers, null, "handlers set to null");
OpenLayers.Control.prototype.destroy = temp;
}
function test_Control_Navigation_disableZoomBox(t) {
t.plan(2);
var nav = new OpenLayers.Control.Navigation();
var zb = new OpenLayers.Control.ZoomBox({});
nav.zoomBox = zb;
zb.activate();
nav.disableZoomBox();
t.eq(nav.zoomBoxEnabled, false, "zoom box deactivated");
t.eq(zb.active, false, "zoom box control deactivated");
}
function test_Control_Navigation_enableZoomBox(t) {
t.plan(2);
var nav = new OpenLayers.Control.Navigation();
var zb = new OpenLayers.Control.ZoomBox({});
nav.zoomBox = zb;
nav.active = true;
nav.enableZoomBox();
t.eq(nav.zoomBoxEnabled, true, "zoom box activated");
t.eq(zb.active, true, "zoom box control activated");
}
function test_Control_Navigation_disableZoomWheel(t) {
t.plan(2);
var nav = new OpenLayers.Control.Navigation();
var wheel = new OpenLayers.Handler.MouseWheel(nav, {});
nav.handlers.wheel = wheel;
wheel.register = function() {};
wheel.unregister = function() {};
wheel.activate();
nav.disableZoomWheel();
t.eq(nav.zoomWheelEnabled, false, "mouse wheel deactivated");
t.eq(wheel.active, false, "mouse wheel handler deactivated");
}
function test_Control_Navigation_enableZoomWheel(t) {
t.plan(2);
var nav = new OpenLayers.Control.Navigation({zoomWheelEnabled: false});
nav.active = true;
var wheel = new OpenLayers.Handler.MouseWheel(nav, {});
wheel.register = function() {};
wheel.unregister = function() {};
nav.handlers.wheel = wheel;
nav.enableZoomWheel();
t.eq(nav.zoomWheelEnabled, true, "mouse wheel activated");
t.eq(wheel.active, true, "mouse wheel handler activated");
}
function test_touches_zoom(t) {
t.plan(3);
var nav = new OpenLayers.Control.Navigation({zoomWheelEnabled: false});
var map = new OpenLayers.Map({
div: "map",
zoomMethod: null,
controls: [nav],
layers: [
new OpenLayers.Layer(null, {isBaseLayer: true})
],
center: new OpenLayers.LonLat(0, 0),
zoom: 3
});
t.eq(map.getZoom(), 3, "map zoom starts at 3");
nav.handlers.click.callback("click", [{lastTouches: ["foo", "bar"]}]);
t.eq(map.getZoom(), 2, "map zooms out with a two touch tap");
nav.handlers.click.callback("click", [{}]);
t.eq(map.getZoom(), 2, "map doesn't do anything with click");
map.destroy();
}
function test_documentDrag(t) {
t.plan(2);
/**
* These tests confirm that the documentDrag property is false by
* default and is passed on to the DragPan control. Tests of panning
* while dragging outside the viewport should go in the DragPan tests.
* Tests of the document events and appropriate callbacks from the
* handler should go in the Drag handler tests.
*/
var nav = new OpenLayers.Control.Navigation();
t.eq(nav.documentDrag, false, "documentDrag false by default");
// nav.destroy(); // fails if called before draw
var map = new OpenLayers.Map({
div: document.body,
controls: [new OpenLayers.Control.Navigation({documentDrag: true})]
});
nav = map.controls[0];
t.eq(nav.dragPan.documentDrag, true, "documentDrag set on the DragPan control");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 256px; height: 256px"></div>
</body>
</html>
|