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:
parent
aaa0721073
commit
20bec613ec
@ -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;
|
||||||
this.setPanOffset(pan);
|
var zoomOffset = map.options.keyboardZoomOffset;
|
||||||
this.setZoomOffset(zoom);
|
|
||||||
|
if (typeof panOffset !== 'number') {
|
||||||
|
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();
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user