From daa76d998c8aa15d7c4d0bf532535a80754e7903 Mon Sep 17 00:00:00 2001 From: alexgao1 Date: Tue, 24 Sep 2024 19:06:38 +0000 Subject: [PATCH] Keyboard controls for map.json config (#1244) * Keyboard controls for map.json config * Set tabindex for map so keyboard controls only in focus * add focus css for map --- .../src/main/js/nunaliit2/css/basic/n2.mapAndControls.css | 4 ++++ nunaliit2-js/src/main/js/nunaliit2/n2.couchModule.js | 3 +++ nunaliit2-js/src/main/js/nunaliit2/n2.mapAndControls.js | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/nunaliit2-js/src/main/js/nunaliit2/css/basic/n2.mapAndControls.css b/nunaliit2-js/src/main/js/nunaliit2/css/basic/n2.mapAndControls.css index 967689cc7..5cba946c6 100644 --- a/nunaliit2-js/src/main/js/nunaliit2/css/basic/n2.mapAndControls.css +++ b/nunaliit2-js/src/main/js/nunaliit2/css/basic/n2.mapAndControls.css @@ -349,3 +349,7 @@ table.mediaSelection td { .olLayerGooglePoweredBy, .gmnoprint, .gm-style-cc { visibility: hidden; } + +.n2_content_map:focus { + border: solid #444444 2px; +} diff --git a/nunaliit2-js/src/main/js/nunaliit2/n2.couchModule.js b/nunaliit2-js/src/main/js/nunaliit2/n2.couchModule.js index 16434b2f6..e12e4f351 100644 --- a/nunaliit2-js/src/main/js/nunaliit2/n2.couchModule.js +++ b/nunaliit2-js/src/main/js/nunaliit2/n2.couchModule.js @@ -1073,6 +1073,8 @@ var ModuleDisplay = $n2.Class({ showSRSAttribution = mapInfo.showSRSAttribution; }; + const enableKeyboardControls = mapInfo.enableKeyboardControls || false + // ScaleLine var scaleLine = { visible: false @@ -1114,6 +1116,7 @@ var ModuleDisplay = $n2.Class({ ,overlays: [] ,toggleClick: toggleClick ,showSRSAttribution: showSRSAttribution + ,enableKeyboardControls: enableKeyboardControls ,scaleLine: scaleLine ,enableWheelZoom: enableWheelZoom ,sidePanelName: _this.sidePanelName diff --git a/nunaliit2-js/src/main/js/nunaliit2/n2.mapAndControls.js b/nunaliit2-js/src/main/js/nunaliit2/n2.mapAndControls.js index 96f880410..86176b74d 100644 --- a/nunaliit2-js/src/main/js/nunaliit2/n2.mapAndControls.js +++ b/nunaliit2-js/src/main/js/nunaliit2/n2.mapAndControls.js @@ -1570,6 +1570,13 @@ var MapAndControls = $n2.Class('MapAndControls',{ this.map.addControl(scaleLine); }; + if (this.options.enableKeyboardControls) { + const keyboardControls = new OpenLayers.Control.KeyboardDefaults() + this.map.div.tabIndex = 0 + keyboardControls.observeElement = this.map.div + this.map.addControl(keyboardControls) + } + // Disable zoom on mouse wheel if( this.options.enableWheelZoom ) { // Do nothing. Enabled by default