1 |
Index: tests/Control/test_KeyboardDefaults.html |
2 |
=================================================================== |
3 |
--- tests/Control/test_KeyboardDefaults.html (Revision 0) |
4 |
+++ tests/Control/test_KeyboardDefaults.html (Revision 0) |
5 |
@@ -0,0 +1,107 @@ |
6 |
+<html> |
7 |
+<head> |
8 |
+ <script src="../../lib/OpenLayers.js"></script> |
9 |
+ <script type="text/javascript"><!-- |
10 |
+ var map; |
11 |
+ function test_01_Control_KeyboardDefaults_constructor (t) { |
12 |
+ t.plan( 1 ); |
13 |
+ |
14 |
+ control = new OpenLayers.Control.KeyboardDefaults(); |
15 |
+ t.ok( control instanceof OpenLayers.Control.KeyboardDefaults, |
16 |
+ "new OpenLayers.Control.KeyboardDefaults returns object" ); |
17 |
+ } |
18 |
+ |
19 |
+ function test_02_Control_KeyboardDefaults_addControl (t) { |
20 |
+ t.plan( 4 ); |
21 |
+ |
22 |
+ map = new OpenLayers.Map('map'); |
23 |
+ control = new OpenLayers.Control.KeyboardDefaults(); |
24 |
+ t.ok( control instanceof OpenLayers.Control.KeyboardDefaults, |
25 |
+ "new OpenLayers.Control.KeyboardDefaults returns object" ); |
26 |
+ t.ok( map instanceof OpenLayers.Map, |
27 |
+ "new OpenLayers.Map creates map" ); |
28 |
+ map.addControl(control); |
29 |
+ t.ok( control.map === map, "Control.map is set to the map object" ); |
30 |
+ t.ok( map.controls[3] === control, "map.controls contains control" ); |
31 |
+ } |
32 |
+ |
33 |
+ function test_03_Control_KeyboardDefaults_KeyDownEvent (t) { |
34 |
+ t.plan( 10 ); |
35 |
+ |
36 |
+ var evt = {which: 1}; |
37 |
+ map = new OpenLayers.Map('map'); |
38 |
+ var layer = new OpenLayers.Layer.WMS("Test Layer", |
39 |
+ "http://octo.metacarta.com/cgi-bin/mapserv?", |
40 |
+ {map: "/mapdata/vmap_wms.map", layers: "basic"}); |
41 |
+ map.addLayer(layer); |
42 |
+ control = new OpenLayers.Control.KeyboardDefaults(); |
43 |
+ map.addControl(control); |
44 |
+ |
45 |
+ var centerLL = new OpenLayers.LonLat(0,0); |
46 |
+ map.setCenter(centerLL,4); |
47 |
+ |
48 |
+ |
49 |
+ evt.keyCode = OpenLayers.Event.KEY_LEFT; |
50 |
+ control.defaultKeyDown(evt); |
51 |
+ t.delay_call( |
52 |
+ 1, function() { |
53 |
+ t.ok( map.getCenter().lon < centerLL.lon, "key left works correctly" ); |
54 |
+ evt.keyCode = OpenLayers.Event.KEY_RIGHT; |
55 |
+ control.defaultKeyDown(evt); |
56 |
+ }, |
57 |
+ 1, function() { |
58 |
+ t.ok( map.getCenter().lon == centerLL.lon, "key right works correctly" ); |
59 |
+ evt.keyCode = OpenLayers.Event.KEY_UP; |
60 |
+ control.defaultKeyDown(evt); |
61 |
+ }, |
62 |
+ 1, function() { |
63 |
+ t.ok( map.getCenter().lat > centerLL.lat, "key up works correctly" ); |
64 |
+ evt.keyCode = OpenLayers.Event.KEY_DOWN; |
65 |
+ control.defaultKeyDown(evt); |
66 |
+ }, |
67 |
+ 1, function() { |
68 |
+ t.ok( map.getCenter().lat == centerLL.lat, "key down works correctly" ); |
69 |
+ evt.keyCode = 33; //page up |
70 |
+ control.defaultKeyDown(evt); |
71 |
+ }, |
72 |
+ 1, function() { |
73 |
+ t.ok( map.getCenter().lat > centerLL.lat, "key page up works correctly" ); |
74 |
+ evt.keyCode = 34; //page down |
75 |
+ control.defaultKeyDown(evt); |
76 |
+ }, |
77 |
+ 1, function() { |
78 |
+ t.ok( map.getCenter().lat == centerLL.lat, "key page down works correctly" ); |
79 |
+ evt.keyCode = 35; //end |
80 |
+ control.defaultKeyDown(evt); |
81 |
+ }, |
82 |
+ 1, function() { |
83 |
+ t.ok( map.getCenter().lon > centerLL.lon, "key end works correctly" ); |
84 |
+ evt.keyCode = 36; //pos1 |
85 |
+ control.defaultKeyDown(evt); |
86 |
+ }, |
87 |
+ 1, function() { |
88 |
+ t.ok( map.getCenter().lon == centerLL.lon, "key pos1 works correctly" ); |
89 |
+ evt.charCode = 43; //+ |
90 |
+ control.defaultKeyDown(evt); |
91 |
+ }, |
92 |
+ 1, function() { |
93 |
+ t.eq( map.getZoom(), 5, "key + works correctly" ); |
94 |
+ // set zoomanimation flag manually, |
95 |
+ // reason: loadend event in layers.js will not achieved in unittests |
96 |
+ map.zoomanimationActive = false; |
97 |
+ evt.charCode = 45; //- |
98 |
+ control.defaultKeyDown(evt); |
99 |
+ }, |
100 |
+ 1, function() { |
101 |
+ t.eq( map.getZoom(), 4, "key - works correctly" ); |
102 |
+ } |
103 |
+ ); |
104 |
+ } |
105 |
+ |
106 |
+ // --> |
107 |
+ </script> |
108 |
+</head> |
109 |
+<body> |
110 |
+ <div id="map" style="width: 1024px; height: 512px;"/> |
111 |
+</body> |
112 |
+</html> |
113 |
Index: lib/OpenLayers/Control/KeyboardDefaults.js |
114 |
=================================================================== |
115 |
--- lib/OpenLayers/Control/KeyboardDefaults.js (Revision 2907) |
116 |
+++ lib/OpenLayers/Control/KeyboardDefaults.js (Arbeitskopie) |
117 |
@@ -14,7 +14,7 @@ |
118 |
OpenLayers.Class.inherit( OpenLayers.Control, { |
119 |
|
120 |
/** @type int */ |
121 |
- slideFactor: 50, |
122 |
+ slideFactor: 75, |
123 |
|
124 |
/** |
125 |
* @constructor |
126 |
@@ -38,26 +38,48 @@ |
127 |
defaultKeyPress: function (code) { |
128 |
switch(code) { |
129 |
case OpenLayers.Event.KEY_LEFT: |
130 |
- this.map.pan(-50, 0); |
131 |
+ this.map.pan(-this.slideFactor, 0); |
132 |
break; |
133 |
case OpenLayers.Event.KEY_RIGHT: |
134 |
- this.map.pan(50, 0); |
135 |
+ this.map.pan(this.slideFactor, 0); |
136 |
break; |
137 |
case OpenLayers.Event.KEY_UP: |
138 |
- this.map.pan(0, -50); |
139 |
+ this.map.pan(0, -this.slideFactor); |
140 |
break; |
141 |
case OpenLayers.Event.KEY_DOWN: |
142 |
- this.map.pan(0, 50); |
143 |
+ this.map.pan(0, this.slideFactor); |
144 |
break; |
145 |
- case 33: // Page Up |
146 |
- case 43: // + |
147 |
+ |
148 |
+ case 33: // Page Up |
149 |
+ var size = this.map.getSize(); |
150 |
+ this.map.pan(0, -0.75*size.h); |
151 |
+ break; |
152 |
+ case 34: // Page Down |
153 |
+ var size = this.map.getSize(); |
154 |
+ this.map.pan(0, 0.75*size.h); |
155 |
+ break; |
156 |
+ case 35: // End |
157 |
+ var size = this.map.getSize(); |
158 |
+ this.map.pan(0.75*size.w, 0); |
159 |
+ break; |
160 |
+ case 36: // Pos1 |
161 |
+ var size = this.map.getSize(); |
162 |
+ this.map.pan(-0.75*size.w, 0); |
163 |
+ break; |
164 |
+ |
165 |
+ case 43: // + |
166 |
this.map.zoomIn(); |
167 |
+ break; |
168 |
+ case 45: // - |
169 |
+ this.map.zoomOut(); |
170 |
+ break; |
171 |
+ case 107: // + (IE only) |
172 |
+ this.map.zoomIn(); |
173 |
break; |
174 |
- case 45: // - |
175 |
- case 34: // Page Down |
176 |
+ case 109: // - (IE only) |
177 |
this.map.zoomOut(); |
178 |
break; |
179 |
- } |
180 |
+ } |
181 |
}, |
182 |
|
183 |
/** @final @type String */ |