Add start of a KeyboardDefaults class. This works, but because Keyboard events apparently always happen on the document level, I haven't yet figured out how to have them only happen when you're 'focused' on the map, so these are currently off by default. To test them, map.addControl(new OpenLayers.Control.KeyboardDefaults()); in your HTML file.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@214 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-05-20 19:59:50 +00:00
parent e88c6abb1f
commit 334fb4c2ed
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
OpenLayers.Control.KeyboardDefaults = Class.create();
OpenLayers.Control.KeyboardDefaults.prototype =
Object.extend( new OpenLayers.Control(), {
initialize: function() {
OpenLayers.Control.prototype.initialize.apply(this, arguments);
},
draw: function() {
Event.observe(document, 'keypress', this.defaultKeyDown.bind(this.map));
},
/**
* @param {Event} evt
*/
defaultKeyDown: function (evt) {
var i = 0;
switch(evt.keyCode) {
case Event.KEY_LEFT:
var resolution = this.getResolution();
var center = this.getCenter();
this.setCenter(
new OpenLayers.LonLat(center.lon - (resolution * 50),
center.lat)
);
Event.stop(evt);
break;
case Event.KEY_RIGHT:
var resolution = this.getResolution();
var center = this.getCenter();
this.setCenter(
new OpenLayers.LonLat(center.lon + (resolution * 50),
center.lat)
);
Event.stop(evt);
break;
case Event.KEY_UP:
var resolution = this.getResolution();
var center = this.getCenter();
this.setCenter(
new OpenLayers.LonLat(center.lon,
center.lat + (resolution * 50))
);
Event.stop(evt);
break;
case Event.KEY_DOWN:
var resolution = this.getResolution();
var center = this.getCenter();
this.setCenter(
new OpenLayers.LonLat(center.lon,
center.lat - (resolution * 50))
);
Event.stop(evt);
break;
}
}
});