nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

commit 50d84e0fd7e1bf884f8233e1a0075395bc9aa448
parent 3591b527a7b5baa395e3430629b30afd2775a9c4
Author: Sergej Orlov <wladimirych@gmail.com>
Date:   Sun, 17 Nov 2019 22:08:18 +0100

layers.hotkeyes: allow specify layer hotkey using explicit property

Diffstat:
Msrc/lib/leaflet.control.layers.hotkeys/index.js | 23+++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/lib/leaflet.control.layers.hotkeys/index.js b/src/lib/leaflet.control.layers.hotkeys/index.js @@ -1,11 +1,25 @@ import L from 'leaflet'; import './style.css'; +function getLayerHotkey(layer) { + if (!layer || !layer.options) { + return null; + } + let hotkey = layer.options.hotkey; + if (hotkey) { + return hotkey; + } + hotkey = layer.options.code; + if (hotkey && hotkey.length === 1) { + return hotkey; + } +} + function extendLayerName(name, layer) { if (layer.options) { - const code = layer.options.code; - if (code && code.length === 1) { - name += `<span class="layers-control-hotkey">${code}</span>`; + const hotkey = getLayerHotkey(layer); + if (hotkey) { + name += `<span class="layers-control-hotkey">${hotkey}</span>`; } } return name; @@ -67,7 +81,8 @@ function enableHotKeys(control) { const key = String.fromCharCode(e.keyCode); for (let layer of this._layers) { let layerId = L.stamp(layer.layer); - if (layer.layer.options && layer.layer.options.code && layer.layer.options.code.toUpperCase() === key) { + const layerHotkey = getLayerHotkey(layer.layer); + if (layerHotkey === key) { const inputs = this._form.getElementsByTagName('input'); for (let input of [...inputs]) { if (input.layerId === layerId) {