diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-10-22 15:55:18 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-10-27 01:42:01 +0200 |
commit | 958b259bcf7f33f077722c585d048ebf8e868990 (patch) | |
tree | 453c423b91fc2b517301e7e9d4dff79f150466c8 | |
parent | 325a43a428300123acbdab846c324bf4fb20b4e5 (diff) | |
download | server-958b259bcf7f33f077722c585d048ebf8e868990.tar.gz |
Add keyboard shortcuts for zooming.
-rw-r--r-- | public/common/client.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/public/common/client.js b/public/common/client.js index 8e6c27d..02391ec 100644 --- a/public/common/client.js +++ b/public/common/client.js @@ -927,6 +927,7 @@ var update_layout = function () {} const e_scroll = document.querySelector("main") e_scroll.style.touchAction = "none" + e_scroll.tabIndex = 1 // enable keyboard scrolling const e_inner = document.createElement("div") e_inner.id = "pan_zoom_main" @@ -1278,6 +1279,40 @@ var update_layout = function () {} }, { passive: false } ) + + window.addEventListener("keydown", function (event) { + if (event.ctrlKey || event.metaKey) { + switch (event.keyCode) { + // '=' / '+' on various keyboards + case 61: + case 107: + case 187: + case 171: + disable_map_fit() + zoom_to(Math.min(MAX_ZOOM, transform1.scale + 0.1)) + event.preventDefault() + break + // '-' + case 173: + case 109: + case 189: + disable_map_fit() + let win_w = e_scroll.clientWidth + let win_h = e_scroll.clientHeight + let real_min_zoom = Math.min(MIN_ZOOM, win_w / map_w, win_h / map_h) + zoom_to(Math.max(real_min_zoom, transform1.scale - 0.1)) + event.preventDefault() + break + // '0' + case 48: + case 96: + disable_map_fit() + zoom_to(1) + event.preventDefault() + break + } + } + }) })() /* INITIALIZE */ |