]> git.openstreetmap.org Git - rails.git/blob - public/lib/OpenLayers/Control/KeyboardDefaults.js
Get rid of our reprojection code and use OpenLayers reprojection instead.
[rails.git] / public / lib / OpenLayers / Control / KeyboardDefaults.js
1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3  * text of the license. */
4 // @require: OpenLayers/Control.js
5
6 /**
7  * @class
8  */
9 OpenLayers.Control.KeyboardDefaults = Class.create();
10 OpenLayers.Control.KeyboardDefaults.prototype = 
11   Object.extend( new OpenLayers.Control(), {
12
13     /** @type int */
14     slideFactor: 50,
15
16     /**
17      * @constructor
18      */
19     initialize: function() {
20         OpenLayers.Control.prototype.initialize.apply(this, arguments);
21     },
22     
23     /**
24      * 
25      */
26     draw: function() {
27         Event.observe(document, 
28                       'keypress', 
29                       this.defaultKeyDown.bind(this));
30     },
31     
32     /**
33     * @param {Event} evt
34     */
35     defaultKeyDown: function (evt) {
36
37         var slide = this.map.getResolution() * this.slideFactor;
38         var center = this.map.getCenter();
39     
40         var newCenter = center.copyOf();
41
42         switch(evt.keyCode) {
43             case Event.KEY_LEFT:
44                 newCenter = newCenter.add( -slide, 0);
45                 break;
46             case Event.KEY_RIGHT: 
47                 newCenter = newCenter.add( slide, 0);
48                 break;
49             case Event.KEY_UP:
50                 newCenter = newCenter.add( 0, slide);
51                 break;
52             case Event.KEY_DOWN:
53                 newCenter = newCenter.add( 0, -slide);
54                 break;
55         }
56         
57         if (!newCenter.equals(center)) {
58             this.map.setCenter(newCenter);
59             Event.stop(evt);
60         }
61     },
62     
63     /** @final @type String */
64     CLASS_NAME: "OpenLayers.Control.KeyboardDefaults"
65 });