[76] | 1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
---|
| 2 | * full list of contributors). Published under the Clear BSD license. |
---|
| 3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
---|
| 4 | * full text of the license. */ |
---|
| 5 | |
---|
| 6 | /** |
---|
| 7 | * @requires OpenLayers/Control.js |
---|
| 8 | * @requires OpenLayers/Handler/Keyboard.js |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | /** |
---|
| 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. |
---|
| 16 | * |
---|
| 17 | * This control has no visible appearance. |
---|
| 18 | * |
---|
| 19 | * Inherits from: |
---|
| 20 | * - <OpenLayers.Control> |
---|
| 21 | */ |
---|
| 22 | OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, { |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * APIProperty: autoActivate |
---|
| 26 | * {Boolean} Activate the control when it is added to a map. Default is |
---|
| 27 | * true. |
---|
| 28 | */ |
---|
| 29 | autoActivate: true, |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * APIProperty: slideFactor |
---|
| 33 | * Pixels to slide by. |
---|
| 34 | */ |
---|
| 35 | slideFactor: 75, |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * Constructor: OpenLayers.Control.KeyboardDefaults |
---|
| 39 | */ |
---|
| 40 | initialize: function() { |
---|
| 41 | OpenLayers.Control.prototype.initialize.apply(this, arguments); |
---|
| 42 | }, |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * APIMethod: destroy |
---|
| 46 | */ |
---|
| 47 | destroy: function() { |
---|
| 48 | if (this.handler) { |
---|
| 49 | this.handler.destroy(); |
---|
| 50 | } |
---|
| 51 | this.handler = null; |
---|
| 52 | |
---|
| 53 | OpenLayers.Control.prototype.destroy.apply(this, arguments); |
---|
| 54 | }, |
---|
| 55 | |
---|
| 56 | /** |
---|
| 57 | * Method: draw |
---|
| 58 | * Create handler. |
---|
| 59 | */ |
---|
| 60 | draw: function() { |
---|
| 61 | this.handler = new OpenLayers.Handler.Keyboard( this, { |
---|
| 62 | "keydown": this.defaultKeyPress }); |
---|
| 63 | }, |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * Method: defaultKeyPress |
---|
| 67 | * When handling the key event, we only use evt.keyCode. This holds |
---|
| 68 | * some drawbacks, though we get around them below. When interpretting |
---|
| 69 | * the keycodes below (including the comments associated with them), |
---|
| 70 | * consult the URL below. For instance, the Safari browser returns |
---|
| 71 | * "IE keycodes", and so is supported by any keycode labeled "IE". |
---|
| 72 | * |
---|
| 73 | * Very informative URL: |
---|
| 74 | * http://unixpapa.com/js/key.html |
---|
| 75 | * |
---|
| 76 | * Parameters: |
---|
| 77 | * code - {Integer} |
---|
| 78 | */ |
---|
| 79 | defaultKeyPress: function (evt) { |
---|
| 80 | switch(evt.keyCode) { |
---|
| 81 | case OpenLayers.Event.KEY_LEFT: |
---|
| 82 | this.map.pan(-this.slideFactor, 0); |
---|
| 83 | break; |
---|
| 84 | case OpenLayers.Event.KEY_RIGHT: |
---|
| 85 | this.map.pan(this.slideFactor, 0); |
---|
| 86 | break; |
---|
| 87 | case OpenLayers.Event.KEY_UP: |
---|
| 88 | this.map.pan(0, -this.slideFactor); |
---|
| 89 | break; |
---|
| 90 | case OpenLayers.Event.KEY_DOWN: |
---|
| 91 | this.map.pan(0, this.slideFactor); |
---|
| 92 | break; |
---|
| 93 | |
---|
| 94 | case 33: // Page Up. Same in all browsers. |
---|
| 95 | var size = this.map.getSize(); |
---|
| 96 | this.map.pan(0, -0.75*size.h); |
---|
| 97 | break; |
---|
| 98 | case 34: // Page Down. Same in all browsers. |
---|
| 99 | var size = this.map.getSize(); |
---|
| 100 | this.map.pan(0, 0.75*size.h); |
---|
| 101 | break; |
---|
| 102 | case 35: // End. Same in all browsers. |
---|
| 103 | var size = this.map.getSize(); |
---|
| 104 | this.map.pan(0.75*size.w, 0); |
---|
| 105 | break; |
---|
| 106 | case 36: // Home. Same in all browsers. |
---|
| 107 | var size = this.map.getSize(); |
---|
| 108 | this.map.pan(-0.75*size.w, 0); |
---|
| 109 | break; |
---|
| 110 | |
---|
| 111 | case 43: // +/= (ASCII), keypad + (ASCII, Opera) |
---|
| 112 | case 61: // +/= (Mozilla, Opera, some ASCII) |
---|
| 113 | case 187: // +/= (IE) |
---|
| 114 | case 107: // keypad + (IE, Mozilla) |
---|
| 115 | this.map.zoomIn(); |
---|
| 116 | break; |
---|
| 117 | case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera) |
---|
| 118 | case 109: // -/_ (Mozilla), keypad - (Mozilla, IE) |
---|
| 119 | case 189: // -/_ (IE) |
---|
| 120 | case 95: // -/_ (some ASCII) |
---|
| 121 | this.map.zoomOut(); |
---|
| 122 | break; |
---|
| 123 | } |
---|
| 124 | }, |
---|
| 125 | |
---|
| 126 | CLASS_NAME: "OpenLayers.Control.KeyboardDefaults" |
---|
| 127 | }); |
---|