~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Control/KeyboardDefaults.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

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