Support for map.options.keyboardPanOffset and map.options.keyboardZoomOffset. Use these to configure how far the keyboard controls will pan/zoom the map (respectively).

This commit is contained in:
Eric Martinez 2012-05-04 22:31:59 -06:00
parent aaa0721073
commit 20bec613ec

View File

@ -1,5 +1,7 @@
L.Map.mergeOptions({ L.Map.mergeOptions({
keyboard: true keyboard: true,
keyboardPanOffset: 50,
keyboardZoomOffset: 1
}); });
L.Map.Keyboard = L.Handler.extend({ L.Map.Keyboard = L.Handler.extend({
@ -27,15 +29,32 @@ L.Map.Keyboard = L.Handler.extend({
panKeys: {}, panKeys: {},
zoomKeys: {}, zoomKeys: {},
initialize: function (map, pan, zoom) { initialize: function (map) {
this._map = map; this._map = map;
this._container = map._container; this._container = map._container;
var panOffset = map.options.keyboardPanOffset;
var zoomOffset = map.options.keyboardZoomOffset;
this.setPanOffset(pan); if (typeof panOffset !== 'number') {
this.setZoomOffset(zoom); panOffset = 50;
}
if (typeof zoomOffset !== 'number') {
zoomOffset = 1;
}
this._setPanOffset(panOffset);
this._setZoomOffset(zoomOffset);
}, },
setPanOffset: function (pan) { addHooks: function () {
L.DomEvent.addListener(this._container, 'click', this._onClick, this);
},
removeHooks: function () {
L.DomEvent.removeListener(this._container, 'click', this._onClick, this);
},
_setPanOffset: function (pan) {
var panKeys = {}, var panKeys = {},
keyCode = null, keyCode = null,
i = 0; i = 0;
@ -71,7 +90,7 @@ L.Map.Keyboard = L.Handler.extend({
this.panKeys = panKeys; this.panKeys = panKeys;
}, },
setZoomOffset: function (zoom) { _setZoomOffset: function (zoom) {
var zoomKeys = {}, var zoomKeys = {},
keyCode = null, keyCode = null,
i = 0; i = 0;
@ -95,14 +114,6 @@ L.Map.Keyboard = L.Handler.extend({
this.zoomKeys = zoomKeys; this.zoomKeys = zoomKeys;
}, },
addHooks: function () {
L.DomEvent.addListener(this._container, 'click', this._onClick, this);
},
removeHooks: function () {
L.DomEvent.removeListener(this._container, 'click', this._onClick, this);
},
_onClick: function (e) { _onClick: function (e) {
this._addHooks(); this._addHooks();
}, },