1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
7 * @requires OpenLayers/Control.js
8 * @requires OpenLayers/Handler/Keyboard.js
12 * Class: OpenLayers.Control.KeyboardDefaults
13 * The KeyboardDefaults control adds panning and zooming functions, controlled
14 * with the keyboard. By default arrow keys pan, +/- keys zoom & Page Up/Page
15 * Down/Home/End scroll by three quarters of a page.
17 * This control has no visible appearance.
20 * - <OpenLayers.Control>
22 OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
25 * APIProperty: slideFactor
31 * Constructor: OpenLayers.Control.KeyboardDefaults
33 initialize: function() {
34 OpenLayers.Control.prototype.initialize.apply(this, arguments);
42 this.handler.destroy();
46 OpenLayers.Control.prototype.destroy.apply(this, arguments);
54 this.handler = new OpenLayers.Handler.Keyboard( this, {
55 "keydown": this.defaultKeyPress });
60 * Method: defaultKeyPress
61 * When handling the key event, we only use evt.keyCode. This holds
62 * some drawbacks, though we get around them below. When interpretting
63 * the keycodes below (including the comments associated with them),
64 * consult the URL below. For instance, the Safari browser returns
65 * "IE keycodes", and so is supported by any keycode labeled "IE".
67 * Very informative URL:
68 * http://unixpapa.com/js/key.html
73 defaultKeyPress: function (evt) {
75 case OpenLayers.Event.KEY_LEFT:
76 this.map.pan(-this.slideFactor, 0);
78 case OpenLayers.Event.KEY_RIGHT:
79 this.map.pan(this.slideFactor, 0);
81 case OpenLayers.Event.KEY_UP:
82 this.map.pan(0, -this.slideFactor);
84 case OpenLayers.Event.KEY_DOWN:
85 this.map.pan(0, this.slideFactor);
88 case 33: // Page Up. Same in all browsers.
89 var size = this.map.getSize();
90 this.map.pan(0, -0.75*size.h);
92 case 34: // Page Down. Same in all browsers.
93 var size = this.map.getSize();
94 this.map.pan(0, 0.75*size.h);
96 case 35: // End. Same in all browsers.
97 var size = this.map.getSize();
98 this.map.pan(0.75*size.w, 0);
100 case 36: // Home. Same in all browsers.
101 var size = this.map.getSize();
102 this.map.pan(-0.75*size.w, 0);
105 case 43: // +/= (ASCII), keypad + (ASCII, Opera)
106 case 61: // +/= (Mozilla, Opera, some ASCII)
107 case 187: // +/= (IE)
108 case 107: // keypad + (IE, Mozilla)
111 case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera)
112 case 109: // -/_ (Mozilla), keypad - (Mozilla, IE)
113 case 189: // -/_ (IE)
114 case 95: // -/_ (some ASCII)
120 CLASS_NAME: "OpenLayers.Control.KeyboardDefaults"